(๑•͈ᴗ•͈)❀送花给你

C#反射中的Assembly.GetCallingAssembly()方法

GetExecutingAssembly():是指获取调用此方法(GetExecutingAssembly)的方法所在的程序集。

GetCallingAssembly():是指获取调用此方法(GetCallingAssembly)所在方法的方法的程序集。

举例来说:

程序集:Test.dll 有如下类:

namespace Test
{
    public class TestClass
    {

        public static void GetAssemblyName()
        {
            Console.WriteLine(Assembly.GetExecutingAssembly().FullName);
            Console.WriteLine();
            Console.WriteLine(Assembly.GetCallingAssembly().FullName);
        }
    }
}
在控制台应用程序TestAssembly中引用Test.dll程序集,主程序如下:

namespace AssemblyTest
{
    class Program
    {
        static void Main(string[] args)
        {
            Test.TestClass.GetAssemblyName();     
        }

    }
}

输出结果:

Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null

AssemblyTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null

 

https://www.cnblogs.com/cpetcoandy/archive/2011/09/09/2172273.html

posted @ 2021-11-10 09:45  胸前小红花  阅读(681)  评论(0)    收藏  举报