Assembly.GetAssembly(Type) Metódus

Definíció

Lekéri azt a jelenleg betöltött szerelvényt, amelyben a megadott típus definiálva van.

public:
 static System::Reflection::Assembly ^ GetAssembly(Type ^ type);
public static System.Reflection.Assembly? GetAssembly(Type type);
public static System.Reflection.Assembly GetAssembly(Type type);
static member GetAssembly : Type -> System.Reflection.Assembly
Public Shared Function GetAssembly (type As Type) As Assembly

Paraméterek

type
Type

A visszaadott szerelvény egy típusát képviselő objektum.

Válaszok

Az a szerelvény, amelyben a megadott típus definiálva van.

Kivételek

type az null.

Példák

Az alábbi példa lekéri a típust tartalmazó szerelvényt, és megjeleníti annak Int32 nevét és fájlhelyét.

using System;
using System.Reflection;

public class Example2
{
    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

Megjegyzések

A metódus meghívása egyenértékű a tulajdonság értékének lekérésével Type.Assembly . A Type.Assembly tulajdonság azonban általában kiváló teljesítményt nyújt.

A metódus meghívásához rendelkeznie kell egy Type objektummal, ami azt jelenti, hogy az osztályt definiáló szerelvényt már be kell tölteni.

A következőre érvényes: