using System;
using System.Reflection;
namespace TestNameSpace
{
class ProcTime
{
static void Main(string[] args)
{
Assembly assembly = Assembly.GetExecutingAssembly();
Test test = (Test)assembly.CreateInstance("TestNameSpace.Test2");
test.Output();
test = (Test)assembly.CreateInstance("TestNameSpace.Test3");
test.Output();
}
}
abstract class Test
{
public virtual void Output()
{
Console.WriteLine("aaaa");
}
}
class Test2:Test
{
public override void Output()
{
Console.WriteLine("bbbbb");
}
}
class Test3 : Test
{
public override void Output()
{
Console.WriteLine("cccc");
}
}
}
反射赋值
foreach (PropertyInfo p in pps)
{
if (p.PropertyType == typeof(float)) //浮点型
p.SetValue(param, float.Parse(value));
else if (p.PropertyType == typeof(int)) //整型
p.SetValue(param, int.Parse(value));
else if (p.PropertyType == typeof(bool)) //布尔型
p.SetValue(param, value == "1");
else if (p.PropertyType.BaseType == typeof(Enum)) //枚举型
p.SetValue(param, int.Parse(value));
else if (p.PropertyType == typeof(PowerPramerter)) //多功能源参数
{
p.SetValue(param, pparam);
}
else //字符串
p.SetValue(param, node.Attributes[p.Name].Value);
}