I have a class Bar like this:
class Foo : IFoo {
[Range(0,255)]
public int? FooProp {get; set}
}
class Bar : IFoo
{
private Foo foo = new Foo();
public int? FooProp { get { return foo.FooProp; }
set { foo.FooProp= value; } }
}
I need to find the attribute [Range(0,255)] reflecting ONLY on the property Bar.FooProp. I mean, the prop is decorated in the class instance (.. new Foo()) not in the class when I am currently parsing. Infact Bar.FooProp has no attributes
EDIT
I moved attributes on the interface's definition, so what I have to do is parsing the inherited interfaces to find them. I can do that because Bar class must implement IFoo.In this particular case, I'm lucky, but the problem remains when I have no interfaces... I will take note for the next time
foreach(PropertyInfo property in properties)
{
IList<Type> interfaces = property.ReflectedType.GetInterfaces();
IList<CustomAttributeData> attrList;
foreach(Type anInterface in interfaces)
{
IList<PropertyInfo> props = anInterface.GetProperties();
foreach(PropertyInfo prop in props)
{
if(prop.Name.Equals(property.Name))
{
attrList = CustomAttributeData.GetCustomAttributes(prop);
attributes = new StringBuilder();
foreach(CustomAttributeData attrData in attrList)
{
attributes.AppendFormat(ATTR_FORMAT,
GetCustomAttributeFromType(prop));
}
}
}
}