Type.AssemblyQualifiedName Property

Definition

取得類型的組件限定名稱,包含載入 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

Property Value

String

Type 的組件限定名稱,包含載入 Type 的組件名稱,如果目前的執行個體表示泛型類型參數,則為 nullThe 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.

Implements

Examples

下列範例會顯示與類別相關聯的元件名稱,以及該類型的完整名稱。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 方法所傳回的字串,以及 NameFullNameAssemblyQualifiedName 屬性。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

Remarks

類型的元件限定名稱包含類型名稱,包括其命名空間、後面接著逗號和元件的顯示名稱。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.

Note

在 .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.ProcessorArchitecture>。See 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 字元。Escape character.
逗號 (,)Comma (,) 在元件名稱之前。Precedes the Assembly name.
加號 (+)Plus sign (+) 在嵌套類別之前。Precedes a nested class.
句點(.)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 和 Namespace),則加號(+)前面會加上一個 escape 字元(\),以防止它被解讀為嵌套分隔符號。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 將會尋找任何元件中的 TypeGetType 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> 的元件限定型別名稱中(在 Visual Basic 中MyGenericClass(Of Integer)),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.

Applies to

See also