Type.Assembly Propriedade
Definição
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
Valor da propriedade
Uma instância de Assembly que descreve o assembly que contém o tipo atual.An Assembly instance that describes the assembly containing the current type. Para tipos genéricos, a instância descreve o assembly que contém a definição de tipo genérico, não o assembly que cria e usa um tipo construído específico.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.
Implementações
Exemplos
O exemplo a seguir exibe o nome do assembly associado à classe e o nome totalmente qualificado do tipo.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.
Comentários
Se o Type objeto atual representar um tipo genérico construído, essa propriedade retornará o assembly que contém a definição de tipo genérico.If the current Type object represents a constructed generic type, this property returns the assembly that contains the generic type definition. Por exemplo, suponha que você crie um assembly chamado MyGenerics.dll que contém a definição de tipo genérico MyGenericStack<T> ( MyGenericStack(Of T) em Visual Basic, generic<T> ref class MyGenericStack em C++).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++). Se você criar uma instância de MyGenericStack<int> ( MyGenericStack(Of Integer) em Visual Basic) em outro assembly, a Assembly propriedade para o tipo construído retornará um Assembly objeto que representa MyGenerics.dll.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.
Da mesma forma, se o Type objeto atual representar um parâmetro genérico não atribuído T , essa propriedade retornará o assembly que contém o tipo genérico que define 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.
Se a Type.Assembly propriedade não estiver disponível em uma implementação específica do .net, como o .NET Core ou o plataforma universal do Windows, use a TypeInfo.Assembly propriedade em vez disso.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.
Esta propriedade é somente para leitura.This property is read-only.