Type.Assembly 属性

定义

获取在其中声明该类型的 Assembly。 对于泛型类型,则获取在其中定义该泛型类型的 Assembly

C#
public abstract System.Reflection.Assembly Assembly { get; }

属性值

描述包含当前类型的程序集的 Assembly 实例。 对于泛型类型,该实例描述包含泛型类型定义的程序集,而不是创建和使用特定构造类型的程序集。

实现

示例

以下示例显示与 类关联的程序集名称和类型的完全限定名称。

C#
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.

注解

如果当前 Type 对象表示构造的泛型类型,则此属性返回包含泛型类型定义的程序集。 例如,假设你创建一个名为 MyGenerics.dll 的程序集,其中包含 Visual Basic 中的泛型类型定义 MyGenericStack<T> (MyGenericStack(Of T) C generic<T> ref class MyGenericStack ++) 。 如果在另一个程序集的 Visual Basic) 中创建 (MyGenericStack(Of Integer) 实例MyGenericStack<int>Assembly则构造类型的 属性将返回一个Assembly表示MyGenerics.dll的对象。

同样,如果当前 Type 对象表示未分配的泛型参数 T,则此属性返回包含定义 T的泛型类型的程序集。

Type.Assembly如果 属性在特定 .NET 实现(如 .NET Core 或 通用 Windows 平台)上不可用,请改用 TypeInfo.Assembly 属性。

此属性为只读。

适用于

产品 版本
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1