当前位置: 首页>>代码示例>>C#>>正文


C# Assembly.GetExecutingAssembly方法代码示例

本文整理汇总了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));
   }
}
开发者ID:.NET开发者,项目名称:System.Reflection,代码行数:23,代码来源:Assembly.GetExecutingAssembly

输出:

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);
   }
}
开发者ID:.NET开发者,项目名称:System.Reflection,代码行数:12,代码来源:Assembly.GetExecutingAssembly

输出:

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() {
    }
}
开发者ID:C#程序员,项目名称:System.Reflection,代码行数:31,代码来源:Assembly.GetExecutingAssembly


注:本文中的System.Reflection.Assembly.GetExecutingAssembly方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。