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

實作

範例

下列範例會顯示與類別相關聯的組件名稱和型別的完整的名稱。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.
Imports System

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方法和NameFullName,和AssemblyQualifiedName屬性。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
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.

支援通用語言執行平台的所有編譯器都發出的簡單名稱的巢狀類別,並反映建構查詢時,根據下列慣例 mangled 的名稱。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 (.) 表示命名空間識別項。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.Sub+Namespace 則加號 (+) 會加上逸出字元 (\) 以防止它被解譯為巢狀分隔符號。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展開的組件限定類型名稱為Int32For 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.

適用於

另請參閱