小编tim*_*imo的帖子

如何使用私有类型调用方法<T>(Func <Action <T >>操作)

我希望代码剪切说明我的问题.我需要InvokeCallEvent方法就像它在out-comment线中一样.我到没有访问ThirdPartyAnotherThirdParty类.
就我而言:

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 …
Run Code Online (Sandbox Code Playgroud)

c# generics reflection

9
推荐指数
1
解决办法
1259
查看次数

标签 统计

c# ×1

generics ×1

reflection ×1