Type.Assembly Type.Assembly Type.Assembly Type.Assembly Property

定义

获取在其中声明该类型的 AssemblyGets the Assembly in which the type is declared. 对于泛型类型,则获取在其中定义该泛型类型的 AssemblyFor generic types, gets the Assembly in which the generic type is defined.

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 实例。An Assembly instance that describes the assembly containing the current type. 对于泛型类型,该实例描述包含泛型类型定义的程序集,而不是创建和使用特定构造类型的程序集。For generic types, the instance describes the assembly that contains the generic type definition, not the assembly that creates and uses a particular constructed type.

实现

示例

下面的示例显示与类关联的程序集名称和该类型的完全限定名称。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.

注解

如果当前Type对象表示构造泛型类型,则此属性返回包含泛型类型定义的程序集。If the current Type object represents a constructed generic type, this property returns the assembly that contains the generic type definition. 例如,假设你创建了一个名为 MyGenerics 的程序集,该程序集包含MyGenericStack<T>泛型MyGenericStack(Of T)类型定义( generic<T> ref class MyGenericStack在C++中为 Visual Basic)。For example, suppose you create an assembly named MyGenerics.dll that contains the generic type definition MyGenericStack<T> (MyGenericStack(Of T) in Visual Basic, generic<T> ref class MyGenericStack in C++). 如果在另一个程序集中MyGenericStack<int>创建MyGenericStack(Of Integer)的实例(在 Visual Basic 中), Assembly则构造类型的属性将返回Assembly一个表示 MyGenerics 的对象。If you create an instance of MyGenericStack<int> (MyGenericStack(Of Integer) in Visual Basic) in another assembly, the Assembly property for the constructed type returns an Assembly object that represents MyGenerics.dll.

同样,如果当前Type对象表示一个未赋值的泛型参数T,则此属性返回包含定义T的泛型类型的程序集。Similarly, if the current Type object represents an unassigned generic parameter T, this property returns the assembly that contains the generic type that defines T.

如果该Type.Assembly属性在特定 .net 实现(如 .net Core 或通用 Windows 平台)上不可用,请TypeInfo.Assembly改用属性。If the Type.Assembly property is not available on a particular .NET implementation, such as .NET Core or the Universal Windows Platform, use the TypeInfo.Assembly property instead.

此属性是只读的。This property is read-only.

适用于