static void reflectionCallFunc(GameObject original, MyILiveContent component)
{
Assembly asm = Assembly.Load("GameCore"); //程序集的名字,不要后缀
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();
MethodInfo oMethod = t1.GetMethod("Add", BindingFlags.Instance | BindingFlags.NonPublic, null, new Type[] { typeof(MyILiveContent) }, null); //根据方法名获得方法,该方法有一个参数
oMethod.Invoke(oPubClass, new object[] { component }); //调用方法,如果是静态方法则第一个参数为null,并且不需要创建实例
}
原文:https://www.cnblogs.com/lovelyfish/p/10560559.html