473,382 Members | 1,750 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,382 software developers and data experts.

Custom Attributes - Are they implicitly inherited by subclasses?

Lee


public class ClassA
{
[MyCoolAttribute]
private string _FieldName;
public string FieldName
{
get { return _FieldName; }
}
}

public class ClassB: ClassA
{
// [MyCoolAttribute]
// Must be explicity typed in attribute or implicit in
// the base class?
private string _FieldName;
public string FieldName
{
get { return _FieldName; }
}
}

If ClassA implments a custom attribute on one of it's members, do
derived classes automatically get that attribute or must it be
explicitly added?

Thank you,

--
Warm Regards,
Lee

"Upon further investigation it appears that your software is missing
just one thing. It definitely needs more cow bell..."
Mar 3 '06 #1
1 1560
>public class ClassA
{
[MyCoolAttribute]
private string _FieldName;
public string FieldName
{
get { return _FieldName; }
}
}

public class ClassB: ClassA
{
// [MyCoolAttribute]
// Must be explicity typed in attribute or implicit in
// the base class?
private string _FieldName;
public string FieldName
{
get { return _FieldName; }
}
}
Since the base FieldName property isn't virtual you're shadowing the
base property with this new one. They are therefore different members
and no attributes are inherited.

If ClassA implments a custom attribute on one of it's members, do
derived classes automatically get that attribute or must it be
explicitly added?


In general, it depends on the AttributeUsageAttribute.Inherited
setting on the attribute class and how you call GetCustomAttributes.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Mar 3 '06 #2

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

Similar topics

9
by: Francis Avila | last post by:
A little annoyed one day that I couldn't use the statefulness of generators as "resumable functions", I came across Hettinger's PEP 288 (http://www.python.org/peps/pep-0288.html, still listed as...
50
by: Dan Perl | last post by:
There is something with initializing mutable class attributes that I am struggling with. I'll use an example to explain: class Father: attr1=None # this is OK attr2= # this is wrong...
1
by: Alexander Kervero | last post by:
Hi ,today i was reading diveinto python book,in chapter 5 it has a very generic module to get file information,html,mp3s ,etc. The code of the example is here :...
7
by: lovecreatesbeauty | last post by:
The following shortened table comes from a big company's C++ technical document accompanied with its C++ compiler. This company's C++ compiler was/is very popular in Windows platform programming....
3
by: Gigi | last post by:
I'm trying to add a custom property to each row of a table. So I created an HtmlTable called tblClass, I created a new class myRow inherited from HtmlTableRow, to which I added a new member myRow ...
0
by: Helen | last post by:
I've got a set of custom dropdowns that know how to get their values from a datasource. I'm having problems loading the options before the selected option is set. I've got an abstract base class...
1
by: Daniel Klein | last post by:
When creating a custom exception that derives from ApplicationException, why is it necessary to have the 3 basic contructors, i.e. Public Sub New() Public Sub New(ByVal message As String)...
15
by: Sam Kong | last post by:
Hello! I got recently intrigued with JavaScript's prototype-based object-orientation. However, I still don't understand the mechanism clearly. What's the difference between the following...
1
by: =?Utf-8?B?d2luZHNpbQ==?= | last post by:
Hi, I have a custom attribute targing Property: public class StatefulPropertyAttribute : Attribute{} and all the properties marked with will be handled by public...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.