Invoke方法
Invoke
CallEvent
方法就像它是在沒有評論的行。 我沒有訪問
ThirdParty
或
AnotherThirdParty
類。
這是據我來了:
public class ThirdParty
{
private struct MsgType
{ }
private static void AnotherFunc(MsgType msg)
{ }
}
public class AnotherThirdParty
{
public static void CallEvent<T>(Func<int, Action<T>> action, T arg)
{ }
}
public class MyClass
{
public static void Main()
{
Type MsgType = typeof(ThirdParty).GetNestedType(
"MsgType", BindingFlags.Instance | BindingFlags.NonPublic);
object msg = Activator.CreateInstance(MsgType);
MethodInfo CallEvent = typeof(AnotherThirdParty).GetMethod("CallEvent");
CallEvent = CallEvent.MakeGenericMethod(MsgType);
MethodInfo AnotherFunc = typeof(ThirdParty).GetMethod(
"AnotherFunc", BindingFlags.Static | BindingFlags.NonPublic);
CallEvent.Invoke(null, new object[] {???, msg});
//CallEvent<MsgType>((int x) => new Action<MsgType>(AnotherFunc), msg);
// I can't get my head around how to solve this (Action<msgtype>)
}
}
我也試過:
CallEvent.Invoke(null, new object[]
{
new Func<int, Action<object>>((int x) =>
new Action<object>((object y) =>
AnotherFunc.Invoke(null, new object[] { y }))),
msg
});
我得到以下異常:
System.ArgumentException: 類型的對象「系統.Func2 [System.Int32,System.Action1 [System.Object的]] '不能是 轉換爲類型 ' System.Func2 [System.Int32,Sys系統tem.Action1 [第三方+ MSGTYPE]。
我應該怎麼做?
是否'AnotherThirdParty.CallEvent'做了'T' ARG(比它發送過動作除外)什麼? – Clint
是的,它調用另一個方法'的RaiseEvent(T1 ARG1,T3 ARG3,Func鍵>行動,T2 ARG2)其中,T1:INT其中T3:int' –
timo
應該採取什麼廠的功能呢?只需返回每個int或其他東西的方法? –