static void reflectionCallFunc(GameObject original, MyILiveContent component)
{
Assembly asm = Assembly.Load("GameCore"); //程序集的名字,不要后缀
Type t1 = asm.GetType("Yurowm.GameCore.MyILiveContent"); //参数必须是类的全名
object oPubClass = Activator.CreateInstance(t1); //创建类型的实例
//修改内部成员“_original”的值
foreach (PropertyInfo rInfo in t1.GetProperties())
{
if (rInfo.Name == "_original")
{
if (rInfo.CanWrite)
{
rInfo.SetValue(oPubClass, original, null);
}
break;
}
}
component.Initialize();
//根据方法名获得方法,该方法有一个参数:internal void Add(MyILiveContent clone)
MethodInfo oMethod = t1.GetMethod("Add", BindingFlags.Instance | BindingFlags.NonPublic, null, new Type[] { typeof(MyILiveContent) }, null);
//方法需要传入的参数
object[] parameters = new object[] { component };
//调用方法,如果是静态方法则第一个参数为null,并且不需要创建实例
oMethod.Invoke(oPubClass, parameters);
}