using System;
using System.Reflection;
public class Invoker
{
public static void Main()
{
System.Type myType = System.Type.GetType("Demo");//取得系统类型
object obj = Assembly.GetAssembly(myType).CreateInstance("Demo");//创建实例
MethodInfo method = myType.GetMethod("PrintLine");//提取方法信息
method.Invoke(obj, new object[]{"Rookie", 27});//调用方法
method = myType.GetMethod("PrintLine2");//提取另外一个方法,实际应用中是根据不同版本取得同一个方法,而构造不同参数数组
method.Invoke(obj, new object[]{"Rookie", 27, "Rookie personal information."});//调用方法
}
}
public class Demo
{
public Demo()
{
}
//实际应用中老版本的方法
public void PrintLine(string name, int age)
{
System.Console.WriteLine("Name = " + name + "; Age = " + age.ToString());
}
//实际应用中升级版本的方法(名称相同,只是参数个数不同)
public void PrintLine2(string name, int age, string description)
{
System.Console.WriteLine("Name = " + name + "; Age = " + age.ToString() + "; Description = " + description);
}
}
0
0
python 备份文件
UBuntu下安装mysql & 开启远程
bat 读取文本内容用法
设置DataGridView控件DataGridViewComboBoxColumn下拉框默认值
用PS去除图片中文字的6个方法
asp.net 给Button控件设置背景图片
windows下架设SVN服务器并设置开机启动
如何设置svn服务器端的服务开机启动
C#winform中Excel电子表格导入数据库示例