码迷,mamicode.com
首页 > Windows程序 > 详细

C# Assembly

时间:2015-06-10 09:02:39      阅读:165      评论:0      收藏:0      [点我收藏+]

标签:

Assembly是一个包含来程序的名称,版本号,自我描述,文件关联关系和文件位置等信息的一个集合。

可以通过Assembly的信息来获取程序的类,实例等编程需要用到的信息。

新建NamespaceRef。

using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;

namespace NamespaceRef
{
    class Program
    {
        static void Main(string[] args)
        {
            Country cy;
            String assemblyName = @"NamespaceRef";
            string strongClassName = @"NamespaceRef.Chinese";
            // 注意:这里类名必须为强类名
            // assemblyName可以通过工程的AssemblyInfo.cs中找到
            cy = (Country)Assembly.Load(assemblyName).CreateInstance(strongClassName);

            Console.WriteLine(cy.name);
            Console.ReadKey();
        }
    }

    class Country
    {
        public string name;
    }

    class Chinese : Country
    {
        public Chinese()
        {
            name = "你好";
        }
    }

    class America : Country
    {
        public America()
        {
            name = "Hello";
        }
    }
}
可以根据名称来创建指定的对象。这在为设计模式提供了方便。
http://www.cnblogs.com/muou/archive/2009/07/08/1518971.html

https://msdn.microsoft.com/zh-cn/library/system.reflection.assembly.aspx

C# Assembly

标签:

原文地址:http://blog.csdn.net/ilipan/article/details/46431875

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!