473,803 Members | 4,400 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Inherit attribute with interface ?

Hi everybody,

I have write customize attribute TestAttribute

[AttributeUsage( AttributeTarget s.All, Inherited = true)]
public class TestAttribute : Attribute
{
private string name;
public TestAttribute(s tring name)
{
this.name = name;
}
}

[TestAttribute(" Test test")]
public interface TestInterface
{
void function();
}

public class TestClass : TestInterface
{
public void function()...
}

But why TestClass does not inherit TestAttribute from TestInterface ???

Type t = typeof(DerivedC lass);

TestAttribute testAttr = (TestAttribute) Attribute.GetCu stomAttribute(t ,
typeof(TestAttr ibute));

testAttr alway null. Can anybody help me ?
Thanks.
--
Vi
Nov 15 '05 #1
3 2222
Did you try

TestAttribute testAttr = (TestAttribute) Attribute.GetCu stomAttribute(t ,
typeof(TestAttr ibute), true);

[Note the "true" at the end of the call]

The true tells the method to look for this attribute in the full inheritance
chain.

-vJ

"TruongLapV i" <tr*********@ho tmail.com> wrote in message
news:OI******** ******@TK2MSFTN GP12.phx.gbl...
Hi everybody,

I have write customize attribute TestAttribute

[AttributeUsage( AttributeTarget s.All, Inherited = true)]
public class TestAttribute : Attribute
{
private string name;
public TestAttribute(s tring name)
{
this.name = name;
}
}

[TestAttribute(" Test test")]
public interface TestInterface
{
void function();
}

public class TestClass : TestInterface
{
public void function()...
}

But why TestClass does not inherit TestAttribute from TestInterface ???

Type t = typeof(DerivedC lass);

TestAttribute testAttr = (TestAttribute) Attribute.GetCu stomAttribute(t ,
typeof(TestAttr ibute));

testAttr alway null. Can anybody help me ?
Thanks.
--
Vi

Nov 15 '05 #2
Thanks you for answer,
I have try it, but the result is still "null" :(.

"Vijaye Raji" <no************ @hotmail.com> wrote in message
news:eK******** ******@tk2msftn gp13.phx.gbl...
Did you try

TestAttribute testAttr = (TestAttribute) Attribute.GetCu stomAttribute(t ,
typeof(TestAttr ibute), true);

[Note the "true" at the end of the call]

The true tells the method to look for this attribute in the full inheritance chain.

-vJ

Nov 15 '05 #3
100
Hi TruongLap,
It seems like attributes cannot be inherited from interfaces. If you try and
make TestInterface class instead of interface you will find out that
everything works how it suppose to.

B\rgds
100

"TruongLapV i" <tr*********@ho tmail.com> wrote in message
news:OI******** ******@TK2MSFTN GP12.phx.gbl...
Hi everybody,

I have write customize attribute TestAttribute

[AttributeUsage( AttributeTarget s.All, Inherited = true)]
public class TestAttribute : Attribute
{
private string name;
public TestAttribute(s tring name)
{
this.name = name;
}
}

[TestAttribute(" Test test")]
public interface TestInterface
{
void function();
}

public class TestClass : TestInterface
{
public void function()...
}

But why TestClass does not inherit TestAttribute from TestInterface ???

Type t = typeof(DerivedC lass);

TestAttribute testAttr = (TestAttribute) Attribute.GetCu stomAttribute(t ,
typeof(TestAttr ibute));

testAttr alway null. Can anybody help me ?
Thanks.
--
Vi

Nov 15 '05 #4

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

Similar topics

2
9319
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) .
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(); };
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:
19
2449
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() {
0
9703
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9564
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
10548
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...
1
10295
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7604
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5500
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
5629
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4275
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
3798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.