Hi John ,
I really appreciate your quick response.
As you point out my class implements interface
This is My interface declaration
public interface ICatalog
{
[LengthValidator("Basic Unit",FieldLength.Basic),
RequiredValidator("Basic Unit"),
UIAttribute(FieldLength.Basic, true),
EnumAttribute((int)CatalogProperties.BASIC)]
string Basic
{
get;set;
}
}
public class Catalog : ICatalog
{
private string _basic;
public string Basic
{
get
{
return this._basic;
}
set
{
this._basic = value.ToUpper().Trim();
}
}
}
This is how I'm trying to read custom attribute properties in my code where I use catalog
Catalog cat = new Catalog();
UIAttribute[] uiAttrib = null;
PropertyInfo[] itemTypeProperties= null;
itemTypeProperties = cat.GetType().GetProperties();
PropertyInfo propInfo;
for(int i= 0; i < itemTypeProperties.Length; i++ )
{
propInfo = itemTypeProperties;
uiAttrib = (UIAttribute[])propInfo.GetCustomAttributes(typeof(UIAttribute),true);
if(uiAttrib != null && uiAttrib.Length > 0)
{
int i = uiAttrib[0].MaxLength;
}
}
According to your suggestion I have to get class type and use GetInterfaces() to read all the properties definded in the interface , am I right?
If My Class end up implementing multiple interface , I have to get each interfaces and get propoerties and check the custom attribute ?
Since properties are implemented in Catalog class from ICatalog interface , why properites are not directly inheriting the custom attributes defined?
Thanks
Baski.