程序集

 class Program
    {
        static void Main(string[] args)
        {
            //Assembly[] asms =
            //    AppDomain.CurrentDomain.GetAssemblies();
            //foreach (Assembly asm in asms)
            //{
                  //打印程序运行时用到的所有程序集的引用
            //    Console.WriteLine(asm.Location);
            //}

            //string filename = @"D:\我的文档\MyCode\DOTNET\Baidu贴吧发帖机\BaiduFaTieJi

\BaiduFaTieJi\bin\Debug\BaiduFaTieJi.exe";
            string filename = @"D:\我的文档\快盘\传智资料\班级资料\2011年2月28日班\课上代码

\Sln0410\测试程序集\bin\Debug\测试程序集.dll";
            //从文件中加载程序集
            Assembly asm = Assembly.LoadFile(filename);
            //Console.WriteLine(asm.Location);
            Type[] types = asm.GetTypes();//获得程序集中定义的所有类型(定义的类)
            foreach (Type type in types)
            {
                Console.WriteLine(type);
                //获得类定义的属性
                PropertyInfo[] props = type.GetProperties();
                foreach (PropertyInfo prop in props)
                {
                    Console.WriteLine(prop);
                }
            }

            Console.ReadKey();
        }
    }

 

•所有.Net类都是定义在某个Assembly(程序集)中的,.Net基本类是定义在mscorlib.dll中。exe也可以看做是类库,也可以引用。
.net的exe也是Assembly,.net中的exe和dll的区别就是exe中包含入口函数,其他没有区别,exe也可以当成dll那样引用、也可以反编译。
GAC:全局程序集缓存。公用的Assembly放到GAC中。(*)
•Assembly类是对Assembly的描述(*)。
AppDomain.CurrentDomain.GetAssemblies()获得程序所有的Assembly
Assembly.LoadFile(),动态从文件加载Assembly,不需要在编译的时候引用。
 
posted @ 2013-03-17 22:22  Big.Eagle  阅读(131)  评论(0)    收藏  举报