Type.Assembly 屬性

定義

取得宣告此類型的 Assembly。 若為泛型類型,則取得定義此泛型類型的 Assembly

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

屬性值

Assembly 執行個體,描述包含目前類型的組件。 若為泛型類型,則此執行個體描述的是含有泛型類型定義的組件,而不是建立與使用特定建構類型的組件。

實作

範例

下列範例會顯示與 類別相關聯的元件名稱,以及型別的完整名稱。

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.
open System

let objType = typeof<Array>

// Print the assembly full name.
printfn $"Assembly full name:\n   {objType.Assembly.FullName}."

// Print the assembly qualified name.
printfn $"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.

備註

如果目前的 Type 物件代表建構的泛型型別,這個屬性會傳回包含泛型型別定義的元件。 例如,假設您在 C++) 中建立名為 MyGenerics.dll 的元件, generic<T> ref class MyGenericStack 其中包含 Visual Basic 中的泛型型別定義 MyGenericStack<T> (MyGenericStack(Of T) 。 如果您在 Visual Basic) 另一個元件中建立 (MyGenericStack(Of Integer)MyGenericStack<int> 實例, Assembly 建構類型的 屬性會 Assembly 傳回代表MyGenerics.dll的物件。

同樣地,如果目前的 Type 物件代表未指派的泛型參數 T ,這個屬性會傳回包含定義 之泛型型別的 T 元件。

Type.Assembly如果特定 .NET 實作無法使用屬性,例如 .NET Core 或通用 Windows 平臺,請 TypeInfo.Assembly 改用 屬性。

這是唯讀的屬性。

適用於