Assembly.GetExecutingAssembly Metódus
Definíció
Fontos
Egyes információk olyan, kiadás előtti termékekre vonatkoznak, amelyek a kiadásig még jelentősen módosulhatnak. A Microsoft nem vállal kifejezett vagy törvényi garanciát az itt megjelenő információért.
Lekéri az éppen futó kódot tartalmazó szerelvényt.
public:
static System::Reflection::Assembly ^ GetExecutingAssembly();
public static System.Reflection.Assembly GetExecutingAssembly();
static member GetExecutingAssembly : unit -> System.Reflection.Assembly
Public Shared Function GetExecutingAssembly () As Assembly
Válaszok
A jelenleg futó kódot tartalmazó szerelvény.
Példák
Az alábbi példa a tulajdonságot használja az Type.Assembly aktuálisan végrehajtó szerelvény lekéréséhez az adott szerelvényben található típus alapján. A metódust arra is meghívja GetExecutingAssembly , hogy azt mutassa, hogy ugyanazt a szerelvényt Assembly képviselő objektumot ad vissza.
using System;
using System.Reflection;
class Example
{
static void Main()
{
// Get the assembly from a known type in that assembly.
Type t = typeof(Example);
Assembly assemFromType = t.Assembly;
Console.WriteLine("Assembly that contains Example:");
Console.WriteLine(" {0}\n", assemFromType.FullName);
// Get the currently executing assembly.
Assembly currentAssem = Assembly.GetExecutingAssembly();
Console.WriteLine("Currently executing assembly:");
Console.WriteLine(" {0}\n", currentAssem.FullName);
Console.WriteLine("The two Assembly objects are equal: {0}",
assemFromType.Equals(currentAssem));
}
}
// The example displays the following output:
// Assembly that contains Example:
// GetExecutingAssembly1, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
//
// Currently executing assembly:
// GetExecutingAssembly1, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
//
// The two Assembly objects are equal: True
Imports System.Reflection
Public Module Example
Public Sub Main()
' Get the assembly from a known type in that assembly.
Dim t As Type = GetType(Example)
Dim assemFromType As Assembly = t.Assembly
Console.WriteLine("Assembly that contains Example:")
Console.WriteLine(" {0}", assemFromType.FullName)
Console.WriteLine()
' Get the currently executing assembly.
Dim currentAssem As Assembly = Assembly.GetExecutingAssembly()
Console.WriteLine("Currently executing assembly:")
Console.WriteLine(" {0}", currentAssem.FullName)
Console.WriteLine()
Console.WriteLine("The two Assembly objects are equal: {0}",
assemFromType.Equals(currentAssem))
End Sub
End Module
' The example displays the following output:
' Assembly that contains Example:
' GetExecutingAssembly1, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
'
' Currently executing assembly:
' GetExecutingAssembly1, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
'
' The two Assembly objects are equal: True
Megjegyzések
Teljesítménybeli okokból ezt a metódust csak akkor hívhatja meg, ha a tervezéskor nem tudja, hogy éppen melyik szerelvényt hajtja végre. Az aktuális szerelvényt képviselő objektumok lekérésének Assembly ajánlott módja a Type.Assembly szerelvényben található típus tulajdonságának használata, ahogyan az alábbi példa is szemlélteti.
using System;
using System.Reflection;
public class Example
{
public static void Main()
{
Assembly assem = typeof(Example).Assembly;
Console.WriteLine("Assembly name: {0}", assem.FullName);
}
}
// The example displays output like the following:
// Assembly name: Assembly1, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
Imports System.Reflection
Module Example
Public Sub Main()
Dim assem As Assembly = GetType(Example).Assembly
Console.WriteLine("Assembly name: {0}", assem.FullName)
End Sub
End Module
' The example displays the following output:
' Assembly name: Assembly1, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
Az aktuálisan végrehajtó kódnak nevezett metódust tartalmazó szerelvény lekéréséhez használja GetCallingAssemblya következőt: .