473,401 Members | 2,146 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

Interface Properties with Custom Attributes

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
1 8435
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Doug Holland | last post by:
Often you see code where an empty interface is used to indicate something about the class that realizes it. In the .NET world this can be done with custom attributes too, so which is better: ...
12
by: Pol Bawin | last post by:
Hi All, Did somebody already define attributes for numerical properties to define value : minima, maxima, a number of decimal, ...? This information would be useful to unify syntax Polo
0
by: News | last post by:
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 {
2
by: Microsoft | last post by:
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) .
2
by: Alex Sedow | last post by:
Why interface-event-declaration does not support multiple declarators like event-declaration? Grammar from C# spec: variable-declarators: variable-declarator variable-declarators ","...
2
by: Brian | last post by:
NOTE ALSO POSTED IN microsoft.public.dotnet.framework.aspnet.buildingcontrols I have solved most of my Server Control Collection property issues. I wrote an HTML page that describes all of the...
8
by: Bill Rust | last post by:
I've created an "Add Item" wizard for VB.NET 2003 that allows a user to add a specialized class that works with my application framework. In the wizard, the user can select the interfaces they...
5
by: Sergio Montero | last post by:
I have a MustInherits Base class that implements a custom IDataLayer interfase. IDataLayer expose CRUD methods. Base class constructor requires two parameters: ConnectionString TableName ...
5
by: Jon Pope | last post by:
I've got a class which contains properties. I can supply this class to the Properties control, and it will properly display the properties and allow the user to edit them, etc. I would like to be...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.