473,795 Members | 2,452 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to Inherit attribute with interface ?

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) .


Nov 16 '05 #1
2 9317
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) .

Nov 16 '05 #2
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) .


Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2222
by: TruongLapVi | last post by:
Hi everybody, I have write customize attribute TestAttribute public class TestAttribute : Attribute { private string name; public TestAttribute(string name) {
5
1765
by: john conwell | last post by:
I'm trying to make a class that already inherits from a base class, also inherit from an interface in managed C++. so my interface looks like so: __gc interface ITask { __property String* get_Subject(); };
4
428
by: David | last post by:
I have trying to have a webform inherit controls from another form and can't get it to work Say I have a form that saves the person's demographic info. ****one.aspx**** //I have an object to save the person's name in code behind protected void SavePersonInfo(Person p)
2
3487
by: svendtofte | last post by:
Hello, I've used wsdl.exe, to generate stub code for a WS at work. an example of the stub code is: ========================== /// <remarks/> public abstract class NavigatePublicationTarget : System.Web.Services.WebService {
2
1877
by: Niklas | last post by:
Hi Is it possible in one way or another to enforce that a class only inherit from one of the derived interfaces of a base interface of some kind. For example. public class MyClass2 : IMyInterface1 => OK public class MyClass2 : IMyInterface1, IMyInterface2 => Error Regards /Niklas
2
2696
by: Christoph Heindl | last post by:
Hi, I'm currently struggling with a design decision. One of my classes (named Attributable) has a protected member of type std::list<StrongReference<Attribute> > Basically the list has strong references that point to Attribute's. In Attributable i want to provide an stl like interface for bidirectional iterators like:
5
2876
by: Soledad Vel | last post by:
Hi All, i write this code: var sliderwidth=100; var sliderheight = 100; var div1 = document.createElement('div'); div1.setAttribute('id','d5'); div1.setAttribute('style', 'background-color:yellow;position:relative;width:'+sliderwidth+'px;heigh
19
2448
by: zzw8206262001 | last post by:
Hi,I find a way to make javescript more like c++ or pyhon There is the sample code: function Father(self) //every contructor may have "self" argument { self=self?self:this; //every class may have this statement self.hello = function() {
4
1331
by: shawncraig | last post by:
I've written a control and Inherited a button but I only want to show only the custom properties that I made. Is there a way to hide the rest?
0
9519
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10437
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10001
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9042
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5437
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3723
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2920
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.