首页 新闻 赞助 找找看

反射如何获取显式实现的接口方法

0
[已解决问题] 解决于 2016-10-14 13:39
interface ITestInterface
    {
        void Test();
    }

    class TestClass : ITestInterface
    {
        void ITestInterface.Test()
        {
            throw new NotImplementedException();
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            Type t = typeof(TestClass);
            MethodInfo method = t.GetMethod("Test");
        }
    }

method为null,求破

小重山的主页 小重山 | 初学一级 | 园豆:173
提问于:2016-10-13 21:19
< >
分享
最佳答案
0

可以这样

MethodInfo method = t.GetMethod("yournamespace.ITestInterface.Test", BindingFlags.Instance | BindingFlags.NonPublic);

奖励园豆:5
jello chen | 大侠五级 |园豆:7306 | 2016-10-14 09:53
其他回答(1)
0

不知道你要干嘛!

~扎克伯格 | 园豆:1923 (小虾三级) | 2016-10-14 09:28
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册