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

How to write a .NET attribute which does just like ObsoleteAttribute...

Hi,

In .NET there is attribute named ObsoleteAttribute which is derived from
System.Attribute Class. This attribute when applied to a target (class or
method etc.) gives a compiler warning/error. I know we can write our own
attributes by inheriting the System.Attribute but I want to make it give
compiler warning or error when it is applied on the defined attribute
target.

How can we write such an attributes?

Regards,
Ashok G
Jun 27 '08 #1
4 792
You can't... ObsoleteAttribute is handled as a special-case by the
compiler, not by anything extensible.

What do you want to check, in particular? There may be other ways of
doing it...

Marc
Jun 27 '08 #2
On Apr 24, 8:26*am, "AshokG" <gw2ks...@hotmail.comwrote:
Hi,

In .NET there is attribute named ObsoleteAttribute which is derived from
System.Attribute Class. This attribute when applied to a target (class or
method etc.) gives a compiler warning/error. I know we can write our own
attributes by inheriting the System.Attribute but I want to *make it give
compiler warning or error when it is applied on the defined attribute
target.

How can we write such an attributes?

Regards,
Ashok G
Hi,

AFAIK there is no way of doing that. The compiler knows a given number
of attributes and have CODED actions for them.
You would need to write a new compiler :)
Jun 27 '08 #3
Hi Ashok,

I know you can designate code as 'deprecated'.
Simply deprecate the attribute and each usage of it
will probally result in a compiler warning.

(not sure 100% because i have not tried this yet)

Let me know if it works!

Chazz
AshokG schreef:
Hi,

In .NET there is attribute named ObsoleteAttribute which is derived from
System.Attribute Class. This attribute when applied to a target (class or
method etc.) gives a compiler warning/error. I know we can write our own
attributes by inheriting the System.Attribute but I want to make it give
compiler warning or error when it is applied on the defined attribute
target.

How can we write such an attributes?

Regards,
Ashok G

Jun 27 '08 #4
I think I can do something with AST (Abstract Syntax Tree) of the .NET
framework. I don't have complete onfo on .NET's AST.

Regards,
Ashok G

"AshokG" <gw******@hotmail.comwrote in message
news:uT**************@TK2MSFTNGP02.phx.gbl...
Hi,

In .NET there is attribute named ObsoleteAttribute which is derived from
System.Attribute Class. This attribute when applied to a target (class or
method etc.) gives a compiler warning/error. I know we can write our own
attributes by inheriting the System.Attribute but I want to make it give
compiler warning or error when it is applied on the defined attribute
target.

How can we write such an attributes?

Regards,
Ashok G

Jun 27 '08 #5

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

Similar topics

1
by: bdinmstig | last post by:
I refined my attempt a little further, and the following code does seem to work, however it has 2 major problems: 1. Very limited support for XPath features Basic paths are supported for...
2
by: Gabriel Genellina | last post by:
Hi In the following code sample, I have: - a Worker class, which could have a lot of methods and attributes. In particular, it has a 'bar' attribute. This class can be modified as needed. - a...
7
by: svilen | last post by:
hello again. i'm now into using python instead of another language(s) for describing structures of data, including names, structure, type-checks, conversions, value-validations, metadata etc....
13
by: Stumped and Confused | last post by:
Hello, I really, really, need some help here - I've spent hours trying to find a solution. In a nutshell, I'm trying to have a user input a value in form's textfield. The value should then be...
12
by: Radek Maciaszek | last post by:
Hi It's very interesting problem. I couldn't even find any inforamtion about it on the google. I think that the best way of explain will be this simple example: <html> <body> <script...
2
by: Steve James | last post by:
I am trying to mark an override method in a derived class as obsolete using the ObsoleteAttribute. The compiler, however is not picking up this attribute and is not generating a warning or an...
21
by: Raj | last post by:
Hi, We just executed a project with Python using TG. The feedback was to use more python like programming rather than C style code executed in Python. The feedback is from a Python purist and...
2
by: Phill W. | last post by:
Is there already or can I create an Attribute that, when attached to a method, causes a compiler warning at build time? A bit like the ObsoleteAttribute, but more generic. TIA, Phill W.
4
by: AshokG | last post by:
Hi, In .NET there is attribute named ObsoleteAttribute which is derived from System.Attribute Class. This attribute when applied to a target (class or method etc.) gives a compiler...
6
by: Tony Johansson | last post by:
Hello! I have one simple question about attribute. According to the documentation will GetCustomAttributes return all the custom attributes for this assembly public virtual Object...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...

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.