// Get the diagnostic name string for a type. This attempts to reformat the string into something that is essentially human readable. // Returns true if the function is successful. // runtimeTypeHandle represents the type to get a name for // diagnosticName is the name that is returned // // the genericParameterOffsets list is an optional parameter that contains the list of the locations of where generic parameters may be inserted // to make the string represent an instantiated generic. // // For example for Dictionary<K,V>, metadata names the type Dictionary`2, but this function will return Dictionary<,> // For consumers of this function that will be inserting generic arguments, the genericParameterOffsets list is used to find where to insert the generic parameter name. // // That isn't all that interesting for Dictionary, but it becomes substantially more interesting for nested generic types, or types which are compiler named as // those may contain embedded <> pairs and such. public static bool TryGetDiagnosticStringForNamedType(RuntimeTypeHandle runtimeTypeHandle, out String diagnosticName, List <int> genericParameterOffsets) { diagnosticName = null; ExecutionEnvironmentImplementation executionEnvironment = ReflectionExecution.ExecutionEnvironment; MetadataReader reader; TypeReferenceHandle typeReferenceHandle; if (executionEnvironment.TryGetTypeReferenceForNamedType(runtimeTypeHandle, out reader, out typeReferenceHandle)) { diagnosticName = GetTypeFullNameFromTypeRef(typeReferenceHandle, reader, genericParameterOffsets); return(true); } QTypeDefinition qTypeDefinition; if (executionEnvironment.TryGetMetadataForNamedType(runtimeTypeHandle, out qTypeDefinition)) { TryGetFullNameFromTypeDefEcma(qTypeDefinition, genericParameterOffsets, ref diagnosticName); if (diagnosticName != null) { return(true); } if (qTypeDefinition.IsNativeFormatMetadataBased) { TypeDefinitionHandle typeDefinitionHandle = qTypeDefinition.NativeFormatHandle; diagnosticName = GetTypeFullNameFromTypeDef(typeDefinitionHandle, qTypeDefinition.NativeFormatReader, genericParameterOffsets); return(true); } } return(false); }
// Get the diagnostic name string for a type. This attempts to reformat the string into something that is essentially human readable. // Returns true if the function is successful. // runtimeTypeHandle represents the type to get a name for // diagnosticName is the name that is returned // // the genericParameterOffsets list is an optional parameter that contains the list of the locations of where generic parameters may be inserted // to make the string represent an instantiated generic. // // For example for Dictionary<K,V>, metadata names the type Dictionary`2, but this function will return Dictionary<,> // For consumers of this function that will be inserting generic arguments, the genericParameterOffsets list is used to find where to insert the generic parameter name. // // That isn't all that interesting for Dictionary, but it becomes substantially more interesting for nested generic types, or types which are compiler named as // those may contain embedded <> pairs and such. public static bool TryGetDiagnosticStringForNamedType(RuntimeTypeHandle runtimeTypeHandle, out String diagnosticName, List <int> genericParameterOffsets) { diagnosticName = null; ExecutionEnvironmentImplementation executionEnvironment = ReflectionExecution.ExecutionEnvironment; MetadataReader reader; TypeReferenceHandle typeReferenceHandle; if (executionEnvironment.TryGetTypeReferenceForNamedType(runtimeTypeHandle, out reader, out typeReferenceHandle)) { diagnosticName = GetTypeFullNameFromTypeRef(typeReferenceHandle, reader, genericParameterOffsets); return(true); } TypeDefinitionHandle typeDefinitionHandle; if (executionEnvironment.TryGetMetadataForNamedType(runtimeTypeHandle, out reader, out typeDefinitionHandle)) { diagnosticName = GetTypeFullNameFromTypeDef(typeDefinitionHandle, reader, genericParameterOffsets); return(true); } return(false); }