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
可以通过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#引用类型,思考
- C#获取CSV文件内容对逗号和引号分隔的处理
- c#选择填空题题库
- C# 简单工厂模式
- 菜鸟学排序算法
- C#学习之接口
- C#获取应用程序版本信息
- C#中的委托(Delegate)和事件(Event)
- c#.NET中容易混淆的委托与接口
- C#向并口设备发送指令以获取并口设备的状态
- C#之委托学习
- 将指定数据写入串口
- C#中为什么要使用委托的?
- C#2.0泛型编程之强制类型转换、继承和泛型
- C# 堆栈和堆 Heap & Stack
- C#读取系统字体颜色与大小的方法
- C#模拟百度登录
- C#实现页面GZip或Deflate压缩的方法
- C# 泛型编程之泛型类、泛型方法、泛型约束
- C#中使用ListView动态添加数据不闪烁并显示当前插入值