Leer en inglés Editar

Compartir a través de


Type.Assembly Property

Definition

Gets the Assembly in which the type is declared. For generic types, gets the Assembly in which the generic type is defined.

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

Property Value

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.

Implements

Examples

The following example displays the assembly name associated with the class and the fully qualified name of the type.

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.

Remarks

If the current Type object represents a constructed generic type, this property returns the assembly that contains the generic type definition. 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++). 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.

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.

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.

Applies to

Producto Versiones
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.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