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
runtime 大牛必备
集成微信支付
webview的使用以及js调用OC传参
ScrollView的坑
iOS 字符串 数组 字典 操作!
Git的使用场景
什么是Runloop?
Cannot subclass final class class com.sun.proxy.$Proxy16
<%@page include%>、<%@include%>、<jsp:include>三者之间的本质区别