Type.AssemblyQualifiedName Type.AssemblyQualifiedName Type.AssemblyQualifiedName Type.AssemblyQualifiedName Property

定义

获取类型的程序集限定名,其中包括从中加载 Type 的程序集的名称。Gets the assembly-qualified name of the type, which includes the name of the assembly from which this Type object was loaded.

public:
 abstract property System::String ^ AssemblyQualifiedName { System::String ^ get(); };
public abstract string AssemblyQualifiedName { get; }
member this.AssemblyQualifiedName : string
Public MustOverride ReadOnly Property AssemblyQualifiedName As String

属性值

Type 的程序集限定名,其中包括从中加载 Type 的程序集的名称;或者为 null(如果当前实例表示泛型类型参数)。The assembly-qualified name of the Type, which includes the name of the assembly from which the Type was loaded, or null if the current instance represents a generic type parameter.

实现

示例

下面的示例显示与类关联的程序集名称和该类型的完全限定名称。The following example displays the assembly name associated with the class and the fully qualified name of the type.

using namespace System;
using namespace System::Reflection;
int main()
{
   Type^ objType = System::Array::typeid;
   
   // Print the full assembly name.
   Console::WriteLine( "Full assembly name: {0}.", objType->Assembly->FullName );
   
   // Print the qualified assembly name.
   Console::WriteLine( "Qualified assembly name: {0}.", objType->AssemblyQualifiedName );
}
// The example displays the following output if run under the .NET Framework 4.5:
//    Full assembly name:
//       mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089.
//    Qualified assembly name:
//       System.Array, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089.
using System;

class MyAssemblyClass
{
    public static void Main()
    {
        Type objType = typeof(Array);

        // Print the assembly full name.
        Console.WriteLine($"Assembly full name:\n   {objType.Assembly.FullName}.");

        // Print the assembly qualified name.
        Console.WriteLine($"Assembly qualified name:\n   {objType.AssemblyQualifiedName}.");
    }
}
// The example displays the following output if run under the .NET Framework 4.5:
//    Assembly full name:
//       mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089.
//    Assembly qualified name:
//       System.Array, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089.
Class Example
    Public Shared Sub Main()
        Dim objType As Type = GetType(Array)

        ' Display the assembly full name.
        Console.WriteLine($"Assembly full name:{vbCrLf}   {objType.Assembly.FullName}.")

        ' Display the assembly qualified name.
        Console.WriteLine($"Assembly qualified name:{vbCrLf}   {objType.AssemblyQualifiedName}.")
    End Sub
End Class
' The example displays the following output if run under the .NET Framework 4.5:
'    Assembly full name:
'       mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089.
'    Assembly qualified name:
'       System.Array, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089.

下面的示例ToString将方法返回的字符串Name与、 FullNameAssemblyQualifiedName属性进行比较。The following example compares the strings returned by the ToString method and the Name, FullName, and AssemblyQualifiedName properties.

using System;
using System.Collections.Generic;
using System.Globalization;

public class Example
{
    public static void Main()
    {
        Type t = typeof(String);
        ShowTypeInfo(t);

        t = typeof(List<>);
        ShowTypeInfo(t);

        var list = new List<String>();
        t = list.GetType();
        ShowTypeInfo(t);

        Object v = 12;
        t = v.GetType();
        ShowTypeInfo(t);

        t = typeof(IFormatProvider);
        ShowTypeInfo(t);

        IFormatProvider ifmt = NumberFormatInfo.CurrentInfo;
        t = ifmt.GetType();
        ShowTypeInfo(t);
    }

    private static void ShowTypeInfo(Type t)
    {
        Console.WriteLine($"Name: {t.Name}");
        Console.WriteLine($"Full Name: {t.FullName}");
        Console.WriteLine($"ToString:  {t}");
        Console.WriteLine($"Assembly Qualified Name: {t.AssemblyQualifiedName}");
        Console.WriteLine();
    }
}
// The example displays output like the following:
//    Name: String
//    Full Name: System.String
//    ToString:  System.String
//    Assembly Qualified Name: System.String, mscorlib, Version=4.0.0.0, Culture=neutr
//    al, PublicKeyToken=b77a5c561934e089
//
//    Name: List`1
//    Full Name: System.Collections.Generic.List`1
//    ToString:  System.Collections.Generic.List`1[T]
//    Assembly Qualified Name: System.Collections.Generic.List`1, mscorlib, Version=4.
//    0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
//
//    Name: List`1
//    Full Name: System.Collections.Generic.List`1[[System.String, mscorlib, Version=4
//    .0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]
//    ToString:  System.Collections.Generic.List`1[System.String]
//    Assembly Qualified Name: System.Collections.Generic.List`1[[System.String, mscor
//    lib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorl
//    ib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
//
//    Name: Int32
//    Full Name: System.Int32
//    ToString:  System.Int32
//    Assembly Qualified Name: System.Int32, mscorlib, Version=4.0.0.0, Culture=neutra
//    l, PublicKeyToken=b77a5c561934e089
//
//    Name: IFormatProvider
//    Full Name: System.IFormatProvider
//    ToString:  System.IFormatProvider
//    Assembly Qualified Name: System.IFormatProvider, mscorlib, Version=4.0.0.0, Cult
//    ure=neutral, PublicKeyToken=b77a5c561934e089
//
//    Name: NumberFormatInfo
//    Full Name: System.Globalization.NumberFormatInfo
//    ToString:  System.Globalization.NumberFormatInfo
//    Assembly Qualified Name: System.Globalization.NumberFormatInfo, mscorlib, Versio
//    n=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
Imports System.Collections.Generic
Imports System.Globalization

Module Example
    Public Sub Main()
        Dim t As Type = GetType(String)
        ShowTypeInfo(t)

        t = GetType(List(Of))
        ShowTypeInfo(t)

        Dim list As New List(Of String)()
        t = list.GetType()
        ShowTypeInfo(t)

        Dim v As Object = 12
        t = v.GetType()
        ShowTypeInfo(t)

        t = GetType(IFormatProvider)
        ShowTypeInfo(t)

        Dim ifmt As IFormatProvider = NumberFormatInfo.CurrentInfo
        t = ifmt.GetType()
        ShowTypeInfo(t)
    End Sub

    Private Sub ShowTypeInfo(t As Type)
        Console.WriteLine($"Name: {t.Name}")
        Console.WriteLine($"Full Name: {t.FullName}")
        Console.WriteLine($"ToString:  {t}")
        Console.WriteLine($"Assembly Qualified Name: {t.AssemblyQualifiedName}")
        Console.WriteLine()
    End Sub
End Module
' The example displays output like the following:
'    Name: String
'    Full Name: System.String
'    ToString:  System.String
'    Assembly Qualified Name: System.String, mscorlib, Version=4.0.0.0, Culture=neutr
'    al, PublicKeyToken=b77a5c561934e089
'
'    Name: List`1
'    Full Name: System.Collections.Generic.List`1
'    ToString:  System.Collections.Generic.List`1[T]
'    Assembly Qualified Name: System.Collections.Generic.List`1, mscorlib, Version=4.
'    0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
'
'    Name: List`1
'    Full Name: System.Collections.Generic.List`1[[System.String, mscorlib, Version=4
'    .0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]
'    ToString:  System.Collections.Generic.List`1[System.String]
'    Assembly Qualified Name: System.Collections.Generic.List`1[[System.String, mscor
'    lib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorl
'    ib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
'
'    Name: Int32
'    Full Name: System.Int32
'    ToString:  System.Int32
'    Assembly Qualified Name: System.Int32, mscorlib, Version=4.0.0.0, Culture=neutra
'    l, PublicKeyToken=b77a5c561934e089
'
'    Name: IFormatProvider
'    Full Name: System.IFormatProvider
'    ToString:  System.IFormatProvider
'    Assembly Qualified Name: System.IFormatProvider, mscorlib, Version=4.0.0.0, Cult
'    ure=neutral, PublicKeyToken=b77a5c561934e089
'
'    Name: NumberFormatInfo
'    Full Name: System.Globalization.NumberFormatInfo
'    ToString:  System.Globalization.NumberFormatInfo
'    Assembly Qualified Name: System.Globalization.NumberFormatInfo, mscorlib, Versio
'    n=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

注解

类型的程序集限定名称包含类型名称(包括其命名空间),后跟一个逗号,然后是程序集的显示名称。The assembly-qualified name of a type consists of the type name, including its namespace, followed by a comma, followed by the display name of the assembly. 使用Assembly.FullName属性获取程序集的显示名称。The display name of an assembly is obtained using the Assembly.FullName property.

备注

在 .NET Framework 版本2.0 中,处理器体系结构添加到程序集标识,并可指定为程序集名称字符串的一部分。In the .NET Framework version 2.0, processor architecture is added to assembly identity, and can be specified as part of assembly name strings. 例如,"ProcessorArchitecture = msil"。For example, "ProcessorArchitecture=msil". 不过,由于兼容性原因,它不包含在由AssemblyQualifiedName属性返回的字符串中。However, it is not included in the string returned by the AssemblyQualifiedName property, for compatibility reasons. 请参阅 AssemblyName.ProcessorArchitectureSee AssemblyName.ProcessorArchitecture.

所有支持公共语言运行时的编译器都发出嵌套类的简单名称,并且在查询时,反射将按照以下约定构造错位的名称。All compilers that support the common language runtime emit the simple name of a nested class, and reflection constructs a mangled name when queried, in accordance with the following conventions.

后面Delimiter 含义Meaning
反斜杠 (\)Backslash (\) 转义符。Escape character.
逗号(,)Comma (,) 在程序集名称之前。Precedes the Assembly name.
加号(+)Plus sign (+) 在嵌套类之前。Precedes a nested class.
Period (.)Period (.) 表示命名空间标识符。Denotes namespace identifiers.
方括号([])Brackets ([]) 在类型名称后,表示该类型的数组。After a type name, denotes an array of that type.

-or-

对于泛型类型,包含泛型类型参数列表。For a generic type, encloses the generic type argument list.

- 或 --or-

在类型参数列表中,包含程序集限定的类型。Within a type argument list, encloses an assembly-qualified type.

例如,类的程序集限定名称可能如下所示:For example, the assembly-qualified name for a class might look like this:

TopNamespace.SubNameSpace.ContainingClass+NestedClass, MyAssembly, Version=1.3.0.0, Culture=neutral, PublicKeyToken=b17a5c561934e089  

如果命名空间包含加号(例如 TopNamespace + 命名空间),则加号(+)前面将有一个转义符\(),以防止将其解释为嵌套分隔符。If the namespace contained a plus sign, for example TopNamespace.Sub+Namespace, then the plus sign (+) would be preceded by an escape character (\) to prevent it from being interpreted as a nesting separator. 反射会按如下所示发出此字符串:Reflection would emit this string as follows:

TopNamespace.Sub\+Namespace.ContainingClass+NestedClass, MyAssembly, Version=1.3.0.0, Culture=neutral, PublicKeyToken=b17a5c561934e089   

"+ +"\变成 "\++\\",而""\变成 ""。A "++" becomes "\+\+", and a "\" becomes "\\".

此限定名称可以保留,以后用于加载TypeThis qualified name can be persisted and later used to load the Type. 若要搜索并加载Type,请将与类型名称一起使用,或者使用GetType带有程序集限定类型名称的。To search for and load a Type, use GetType either with the type name only or with the assembly qualified type name. GetType只有类型名称才会Type在调用方的程序集中查找,然后在系统程序集中查找。GetType with the type name only will look for the Type in the caller's assembly and then in the System assembly. GetType具有程序集限定类型名称的将Type在任何程序集中查找。GetType with the assembly qualified type name will look for the Type in any assembly.

类型名称可能包含表示类型附加信息的尾随字符,如类型是引用类型、指针类型还是数组类型。Type names may include trailing characters that denote additional information about the type, such as whether the type is a reference type, a pointer type or an array type. 若要检索不包含这些尾随字符的类型名称t.GetElementType().ToString(),请t使用,其中是类型。To retrieve the type name without these trailing characters, use t.GetElementType().ToString(), where t is the type.

空格在除程序集名称之外的所有类型名称组件中都是相关的。Spaces are relevant in all type name components except the assembly name. 在程序集名称中,"," 分隔符前面的空格是相关的,但 "," 分隔符后面的空格将被忽略。In the assembly name, spaces before the ',' separator are relevant, but spaces after the ',' separator are ignored.

泛型类型的泛型参数本身由程序集名称限定。Generic arguments of generic types are themselves qualified by assembly name. 例如,在的程序集限定类型MyGenericClass<int>名称(MyGenericClass(Of Integer)在 Visual Basic 中)中, int扩展Int32为的程序集限定类型名称。For example, in the assembly-qualified type name for MyGenericClass<int> (MyGenericClass(Of Integer) in Visual Basic), int is expanded to the assembly-qualified type name for Int32.

如果当前Type对象表示泛型参数,则此属性返回nullIf the current Type object represents a generic parameter, this property returns null.

适用于

另请参阅