GetExecutingAssembly Methode
Dieser Artikel wurde maschinell übersetzt. Wenn Sie die englische Version des Artikels anzeigen möchten, aktivieren Sie das Kontrollkästchen Englisch. Sie können den englischen Text auch in einem Popupfenster anzeigen, indem Sie den Mauszeiger über den Text bewegen.
Übersetzung
Englisch

Assembly.GetExecutingAssembly-Methode ()

 

Ruft die Assembly ab, die den derzeit ausgeführten Code enthält.

Namespace:   System.Reflection
Assembly:  mscorlib (in mscorlib.dll)

public static Assembly GetExecutingAssembly()

Rückgabewert

Type: System.Reflection.Assembly

Die Assembly, die den derzeit ausgeführten Code enthält.

For performance reasons, you should call this method only when you do not know at design time what assembly is currently executing. The recommended way to retrieve an T:System.Reflection.Assembly object that represents the current assembly is to use the P:System.Type.Assembly property of a type found in the assembly, as the following example illustrates.

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

To get the assembly that contains the method that called the currently executing code, use M:System.Reflection.Assembly.GetCallingAssembly.

The following example uses the P:System.Type.Assembly property to get the currently executing assembly based on a type contained in that assembly. It also calls the M:System.Reflection.Assembly.GetExecutingAssembly method to show that it returns an T:System.Reflection.Assembly object that represents the same assembly.

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

.NET Framework
Verfügbar seit 1.1
Portable Class Library
Unterstützt in: portable .NET platforms
Silverlight
Verfügbar seit 2.0
Windows Phone Silverlight
Verfügbar seit 7.0
Zurück zum Anfang
Anzeigen:
© 2016 Microsoft