By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,222 Members | 1,437 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,222 IT Pros & Developers. It's quick & easy.

Interface Properties with Custom Attributes

P: n/a
Hello there,

I have following situation , how can I solve this puzzle in
C#.

I have interface called IVendor with some custom attributes applied to it

interface IVendor
{
[LengthValidator("Vendor
Name",FieldLength.Vendor),RequiredValidator("Vendo r Name")]
string Name
{ get;set}

[LengthValidator("Vendor
Number",FieldLength.Vendor),RequiredValidator("Ven dor Number")]
string Number
{
get;set;
}

}
Q 1. I have clas called Vendor , Which implement IVendor interface

Vendor : IVendor
{

}

after I implement all the interface , when I try to get the custom
attributes defined in IVedndor interface thru reflection,
I don't see any of my attributes. How can I inherit my custom attribute from
Interface to the class which implements the interface(Eventhoug it's Meta
data) ?

Q 2 : I have another class callled Invoice Which also implements IVendor
Interface and contains Vendor as inner class,

public class Invoice : IVendor
{
private Vendor _vendor;

}

How can I forward all the properties defined in IVendor infterface to inner
Vendor class peoperties, without reimplementing those interface in Invoice
class?

Thanks
Baski



Nov 15 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Sorry this is a bug which is fixed in the next version of CLR.
Basically we were unable to get CustomAttribute on PropertyInfo and
EvenInfo on inheritance hierarchy.

You can try to define your own wrapper of GetCustomAttribute on
property so that it will walk the inheritance hierarchy by using
reflection APIs.

Sorry about this.

Yiru
"Microsoft" <ba***@aldensys.com> wrote in message news:<eX**************@TK2MSFTNGP10.phx.gbl>...
Hello there,

I have following situation , how can I solve this puzzle in
C#.

I have interface called IVendor with some custom attributes applied to it

interface IVendor
{
[LengthValidator("Vendor
Name",FieldLength.Vendor),RequiredValidator("Vendo r Name")]
string Name
{ get;set}

[LengthValidator("Vendor
Number",FieldLength.Vendor),RequiredValidator("Ven dor Number")]
string Number
{
get;set;
}

}
Q 1. I have clas called Vendor , Which implement IVendor interface

Vendor : IVendor
{

}

after I implement all the interface , when I try to get the custom
attributes defined in IVedndor interface thru reflection,
I don't see any of my attributes. How can I inherit my custom attribute from
Interface to the class which implements the interface(Eventhoug it's Meta
data) ?

Q 2 : I have another class callled Invoice Which also implements IVendor
Interface and contains Vendor as inner class,

public class Invoice : IVendor
{
private Vendor _vendor;

}

How can I forward all the properties defined in IVendor infterface to inner
Vendor class peoperties, without reimplementing those interface in Invoice
class?

Thanks
Baski

Nov 15 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.