您的位置:首页 > 编程语言 > C#

C# Assembly

2015-06-09 21:21 316 查看
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: