Udostępnij za pośrednictwem


Compilation.GetTypeByMetadataName(String) Method

Definition

Gets the type within the compilation's assembly and all referenced assemblies (other than those that can only be referenced via an extern alias) using its canonical CLR metadata name. This lookup follows the following order:

  1. If the type is found in the compilation's assembly, that type is returned.
  2. Next, the core library (the library that defines System.Object and has no assembly references) is searched. If the type is found there, that type is returned.
  3. Finally, all remaining referenced non-extern assemblies are searched. If one and only one type matching the provided metadata name is found, that single type is returned. Accessibility is ignored for this check.
public:
 Microsoft::CodeAnalysis::INamedTypeSymbol ^ GetTypeByMetadataName(System::String ^ fullyQualifiedMetadataName);
public Microsoft.CodeAnalysis.INamedTypeSymbol GetTypeByMetadataName (string fullyQualifiedMetadataName);
public Microsoft.CodeAnalysis.INamedTypeSymbol? GetTypeByMetadataName (string fullyQualifiedMetadataName);
member this.GetTypeByMetadataName : string -> Microsoft.CodeAnalysis.INamedTypeSymbol
Public Function GetTypeByMetadataName (fullyQualifiedMetadataName As String) As INamedTypeSymbol

Parameters

fullyQualifiedMetadataName
String

Returns

Null if the type can't be found or there was an ambiguity during lookup.

Remarks

Since VB does not have the concept of extern aliases, it considers all referenced assemblies.

In C#, if the core library is referenced as an extern assembly, it will be searched. All other extern-aliased assemblies will not be searched.

Because accessibility to the current assembly is ignored when searching for types that match the provided metadata name, if multiple referenced assemblies define the same type symbol (as often happens when users copy well-known types from the BCL or other sources) then this API will return null, even if all but one of those symbols would be otherwise inaccessible to user-written code in the current assembly. For fine-grained control over ambiguity resolution, consider using GetTypesByMetadataName(String) instead and filtering the results for the symbol required.

Assemblies can contain multiple modules. Within each assembly, the search is performed based on module's position in the module list of that assembly. When a match is found in one module in an assembly, no further modules within that assembly are searched.

Type forwarders are ignored, and not considered part of the assembly where the TypeForwardAttribute is written.

Ambiguities are detected on each nested level. For example, if A+B is requested, and there are multiple As but only one of them has a B nested type, the lookup will be considered ambiguous and null will be returned.

Applies to