Assembly.GetAssembly(Type) Assembly.GetAssembly(Type) Assembly.GetAssembly(Type) Method

Definition

Ruft die derzeit geladene Assembly ab, in der der angegebene Typ definiert ist.Gets the currently loaded assembly in which the specified type is defined.

public:
 static System::Reflection::Assembly ^ GetAssembly(Type ^ type);
public static System.Reflection.Assembly GetAssembly (Type type);
static member GetAssembly : Type -> System.Reflection.Assembly

Parameter

type
Type Type Type

Ein Objekt, das einen Typ in der Assembly darstellt, die zurückgegeben wird.An object representing a type in the assembly that will be returned.

Gibt zurück

Die Assembly, in der der angegebene Typ definiert ist.The assembly in which the specified type is defined.

Ausnahmen

Beispiele

Das folgende Beispiel ruft die Assembly ab, die den Int32 -Typ enthält, und zeigt den Namen und den Datei Speicherort an.The following example retrieves the assembly that contains the Int32 type and displays its name and file location.

using namespace System;
using namespace System::Reflection;

void main()
{
   // Get a Type object.
   Type^ t = int::typeid;
   // Instantiate an Assembly class to the assembly housing the Integer type.
   Assembly^ assem = Assembly::GetAssembly(t);
   // Display the name of the assembly.
   Console::WriteLine("Name: {0}", assem->FullName);
   // Get the location of the assembly using the file: protocol.
   Console::WriteLine("CodeBase: {0}", assem->CodeBase);
}
// The example displays output like the following:
//    Name: mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
//    CodeBase: file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/mscorlib.dll
using System;
using System.Reflection;

public class Example
{
   public static void Main()
   {
      // Get a Type object.
      Type t = typeof(int);
      // Instantiate an Assembly class to the assembly housing the Integer type.
      Assembly assem = Assembly.GetAssembly(t);
      // Display the name of the assembly.
      Console.WriteLine("Name: {0}", assem.FullName);
      // Get the location of the assembly using the file: protocol.
      Console.WriteLine("CodeBase: {0}", assem.CodeBase);
   }
}
// The example displays output like the following:
//    Name: mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
//    CodeBase: file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/mscorlib.dll
Imports System.Reflection

Module Example
   Public Sub Main()
      ' Get a Type object.
      Dim t As Type = GetType(Integer)
      ' Instantiate an Assembly class to the assembly housing the Integer type.
      Dim assem As Assembly = Assembly.GetAssembly(t)
      ' Display the name of the assembly.
      Console.WriteLine("Name: {0}", assem.FullName)
      ' Get the location of the assembly using the file: protocol.
      Console.WriteLine("CodeBase: {0}", assem.CodeBase)
   End Sub
End Module
' The example displays output like the following:
'    Name: mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
'    CodeBase: file:'/C:/Windows/Microsoft.NET/Framework64/v4.0.30319/mscorlib.dll

Hinweise

Das Aufrufen dieser Methode entspricht dem Abrufen des Werts Type.Assembly der-Eigenschaft.Calling this method is equivalent to retrieving the value of the Type.Assembly property. Die-Eigenschaft Type.Assembly bietet jedoch in der Regel eine bessere Leistung.However, the Type.Assembly property typically offers superior performance.

Um diese Methode aufzurufen, müssen Sie über ein Type -Objekt verfügen. Dies bedeutet, dass die Assembly, in der die Klasse definiert ist, bereits geladen ist.In order to call this method, you must have a Type object, which means that the assembly in which the class is defined must already be loaded.

Sicherheit

ReflectionPermission
Wenn Sie spät gebunden durch Mechanismen wie InvokeMember(String, BindingFlags, Binder, Object, Object[], ParameterModifier[], CultureInfo, String[])aufgerufen wird.when invoked late-bound through mechanisms such as InvokeMember(String, BindingFlags, Binder, Object, Object[], ParameterModifier[], CultureInfo, String[]). Zugehörige Enumeration:MemberAccessAssociated enumeration: MemberAccess

Gilt für: