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);
}