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",FieldLeng th.Basic),
RequiredValidat or("Basic Unit"),
UIAttribute(Fie ldLength.Basic, true),
EnumAttribute(( int)CatalogProp erties.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[] itemTypePropert ies= null;
itemTypePropert ies = cat.GetType().G etProperties();
PropertyInfo propInfo;
for(int i= 0; i < itemTypePropert ies.Length; i++ )
{
propInfo = itemTypePropert ies[i];
uiAttrib = (UIAttribute[])propInfo.GetCu stomAttributes( typeof(UIAttrib ute),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.
"John Wood" <john.wood@prio rganize_nospam_ _.com> wrote in message news:ee******** ******@TK2MSFTN GP14.phx.gbl...
Are you looking for attributes on the class, or on the interface?
Remember that classes don't "inherit" interfaces, they implement them. If
you want to get the attributes of an interface implemented by your class,
you'll get have to do a GetInterfaces on the class type, and then use that
type to get hold of your attribute.
John Wood
Blog: http://spaces.msn.com/members/johnwood
"Microsoft" <ba***@aldensys .com> wrote in message
news:e5******** ******@TK2MSFTN GP15.phx.gbl... I have Interface defined with custom attribute. My class implements the
same interface , but I'm not able to see any attributes derived from
interface.( I did set the inherited to true) .