The type parameter name of unbound generic type has not consistent naming conventions #741
-
BackgroundWe use this library to generate APIs for our project mdoc. Recently we encountered an issue that's typeof operator with unbound generic type. We need to identify whether a TypeReference is an unbound generic type. Currently, we use TypeReference.GenericParameters.Name to determine whether it is an unbound generic type if it is an unbound generic type that the parameter name will be named ![n], but sometimes some unbound generic type does not follow the naming conventions that the parameter name will be named the type parameter name of the generic type(e.g., TKey, TValue). It looks like is an issue, I wrote an example code to reproduce the issue. Do you have other solutions to help us identify an unbound generic type? Example Code
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi, The difference you're seeing between the In the metadata, the name of the generic parameters are not referenced between modules, only their position. So if you want to be consistent, you need to resolve the TypeReference into a TypeDefinition from its module to look at its generic parameters to get the original generic parameter name. |
Beta Was this translation helpful? Give feedback.
Hi,
The difference you're seeing between the
Dictionary<>
and yourMockDictionary<>
is that Dictionary<> is defined in another module (and thus is represented as aTypeReference
), while MockDictionary<> is defined in the current module (and thus is represented as aTypeDefinition
.In the metadata, the name of the generic parameters are not referenced between modules, only their position.
So if you want to be consistent, you need to resolve the TypeReference into a TypeDefinition from its module to look at its generic parameters to get the original generic parameter name.