473,395 Members | 1,783 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,395 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 1139
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: John | last post by:
I have an input document that contains a large base64 encoded document. This document also declares a schema location in the root element. I want to write an XSL stylesheet that makes an exact...
2
by: Jack | last post by:
Hi, I am trying to check for the final sql statement before passing it to a database. I want to build the statement using user input in three text boxes. However, the sql statement does not give...
12
by: Jens Thiel | last post by:
Hi, is there a reason for C# to require attribute arguments (properties) to be read-write while VB and C++ are happy with only a setter? Simplified Example: public sealed class FooAttribute...
0
by: KathyB | last post by:
Hi, since there doesn't appear to be a way to get the individual elements that make up the xpath to a result node, I'm trying to create an xpath that will result in selecting this xml node which...
0
by: NetronProject | last post by:
My control inherites from ScrollableControl and overrides the BackColor property. The DescriptionFromAttribute inherits from the DescriptionAttribute to return localized information. The same for...
2
by: mario | last post by:
Hi, I have verry big problem. I must write function using dates. This is a problem: I have some dates for example: 2006-01-01, 2006-02-05, 2006-10-15 etc. then some times: 20sec, 50sec, 45sec...
1
by: mvenkatesan | last post by:
Hi guys I written some values into xml element from datatable. but one one value will set(store) in element attribute how to write attribute value? Thanks in advance Venky
162
by: Sh4wn | last post by:
Hi, first, python is one of my fav languages, and i'll definitely keep developing with it. But, there's 1 one thing what I -really- miss: data hiding. I know member vars are private when you...
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...
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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
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...

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.