假设下面的继承层次结构:
public interface IA
{
int ID { get; set; }
}
public interface IB : IA
{
string Name { get; set; }
}
使用反射并进行以下调用:
typeof(IB).GetProperties(BindingFlags.Public | BindingFlags.Instance)
将只产生接口IB
的属性,即"Name
“。
如果我们在下面的代码上做类似的测试,
public abstract class A
{
public int ID { get; set; }
}
public class B : A
{
public string Name { get; set; }
}
调用typeof(B).GetProperties(BindingFlags.Public | BindingFlags.Instance)
将返回"ID
“和"Name
”的PropertyInfo
对象数组。
有没有一种简单的方法可以像第一个例子那样在继承层次结构中找到接口的所有属性?
https://stackoverflow.com/questions/358835
复制相似问题