本文整理汇总了C#中System.Reflection.Assembly.GetExecutingAssembly方法的典型用法代码示例。如果您正苦于以下问题:C# Assembly.GetExecutingAssembly方法的具体用法?C# Assembly.GetExecutingAssembly怎么用?C# Assembly.GetExecutingAssembly使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.Assembly
的用法示例。
在下文中一共展示了Assembly.GetExecutingAssembly方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
//引入命名空间
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));
}
}
输出:
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
示例2: Main
//引入命名空间
using System;
using System.Reflection;
public class Example
{
public static void Main()
{
Assembly assem = typeof(Example).Assembly;
Console.WriteLine("Assembly name: {0}", assem.FullName);
}
}
输出:
Assembly name: Assembly1, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
示例3: Assembly.GetExecutingAssembly()
//引入命名空间
using System;
using System.IO;
using System.Reflection;
using System.Collections.Generic;
public class Loader {
static Dictionary<string, Assembly> libs = new Dictionary<string, Assembly>();
static void Main() {
AppDomain.CurrentDomain.AssemblyResolve += FindAssem;
Program.Go();
}
static Assembly FindAssem(object sender, ResolveEventArgs args) {
string shortName = new AssemblyName(args.Name).Name;
if (libs.ContainsKey(shortName)) return libs[shortName];
using (Stream s = Assembly.GetExecutingAssembly().GetManifestResourceStream("Libs." + shortName + ".dll")) {
byte[] data = new BinaryReader(s).ReadBytes((int)s.Length);
Assembly a = Assembly.Load(data);
libs[shortName] = a;
return a;
}
}
}
public class Program {
public static void Go() {
}
}