MSFakes Naming Convention to match Generic class?

别等时光非礼了梦想. 提交于 2019-12-24 00:55:36

问题


I have a class called MyClass, and a generic version called MyClass<C>. Using fakes, I want to generate a shim of JUST MyClass<C>, and not MyClass. I originally tried:

<Fakes xmlns="http://schemas.microsoft.com/fakes/2011/">
  <Assembly Name="XXXX" Version="#.##.###"/>
  <ShimGeneration>
    <Clear/>
    <Add FullName="MyClass!"/>
  </ShimGeneration>
</Fakes>

This generated shims for MyClass, but not MyClass<C>. If I change the ! to a *, it does match MyClass<C>. This leads me to believe there is some naming convention I need to use to match MyClass<C>. Does anyone know what it is/where I could find out?


回答1:


You use the grave accent character plus the number of generic type parameters on the type. For example: MyClass<T> would be 1, MyClass<T,U> would be 2, etc. See also CLI specification Section 10.7.2 Type names and arity coding.

You should also add your namespace as a part of the value.

<Fakes xmlns="http://schemas.microsoft.com/fakes/2011/">
  <Assembly Name="XXXX" Version="#.##.###"/>
  <ShimGeneration>
    <Clear/>
    <Add FullName="MyNamespace.MyClass`1!"/>
  </ShimGeneration>
</Fakes>


来源:https://stackoverflow.com/questions/46434672/msfakes-naming-convention-to-match-generic-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!