GetProperties() to return all properties for an interface inheritance hierarchy
Posted
by sduplooy
on Stack Overflow
See other posts from Stack Overflow
or by sduplooy
Published on 2008-12-11T09:51:00Z
Indexed on
2010/03/14
22:45 UTC
Read the original article
Hit count: 305
Assuming the following hypothetical inheritance hierarchy:
public interface IA
{
int ID { get; set; }
}
public interface IB : IA
{
string Name { get; set; }
}
Using reflection and making the following call:
typeof(IB).GetProperties(BindingFlags.Public | BindingFlags.Instance)
will only yield the properties of interface IB
, which is "Name
".
If we were to do a similar test on the following code,
public abstract class A
{
public int ID { get; set; }
}
public class B : A
{
public string Name { get; set; }
}
the call typeof(B).GetProperties(BindingFlags.Public | BindingFlags.Instance)
will return an array of PropertyInfo
objects for "ID
" and "Name
".
Is there an easy way to find all the properties in the inheritance hierarchy for interfaces as in the first example?
© Stack Overflow or respective owner