问题
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