如何使用反射来获取显式实现接口的属性? [英] How do I use reflection to get properties explicitly implementing an interface?

查看:181
本文介绍了如何使用反射来获取显式实现接口的属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更具体地说,如果我有:

More specifically, if I have:

public class TempClass : TempInterface
{

    int TempInterface.TempProperty
    {
        get;
        set;
    }
    int TempInterface.TempProperty2
    {
        get;
        set;
    }

    public int TempProperty
    {
        get;
        set;
    }
}

public interface TempInterface
{
    int TempProperty
    {
        get;
        set;
    }
    int TempProperty2
    {
        get;
        set;
    }
}

如何使用反射来获取显式实现TempInterface的属性的所有propertyInfos?

How do I use reflection to get all the propertyInfos for properties explicitly implementing TempInterface?

谢谢.

推荐答案

我不得不修改Jacob Carpenter的答案,但是效果很好. nobugz的也可以,但是Jacobs更为紧凑.

I had to modify Jacob Carpenter's answer but it works nicely. nobugz's also works but Jacobs is more compact.

var explicitProperties =
from method in typeof(TempClass).GetMethods(BindingFlags.NonPublic | BindingFlags.Instance)
where method.IsFinal && method.IsPrivate
select method;

这篇关于如何使用反射来获取显式实现接口的属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆