Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > .NET General

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

Reply
 
Old 04-24-2008   #1 (permalink)
AshokG


 
 

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



My System SpecsSystem Spec
Old 04-24-2008   #2 (permalink)
Marc Gravell


 
 

Re: How to write a .NET attribute which does just likeObsoleteAttribute...

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
My System SpecsSystem Spec
Old 04-24-2008   #3 (permalink)
Ignacio Machin ( .NET/ C# MVP )


 
 

Re: How to write a .NET attribute which does just likeObsoleteAttribute...

On Apr 24, 8:26*am, "AshokG" <gw2ks...@xxxxxx> wrote:
Quote:

> 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
My System SpecsSystem Spec
Old 04-27-2008   #4 (permalink)
Chazz


 
 

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

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:
Quote:

> 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
>
>
My System SpecsSystem Spec
Old 04-28-2008   #5 (permalink)
AshokG


 
 

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

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" <gw2ksoft@xxxxxx> wrote in message
news:uTeKFZgpIHA.1236@xxxxxx
Quote:

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

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
how to get powershell to write to event log or write a log file? PowerShell
Write-Error doesn't write anyting PowerShell
The disk is write-protected. Remove the write-protection or... Vista General
newline in Write-Debug or Write-Verbose PowerShell
How to insert the "modified time" attribute in "date taken" attribute in batch mode-in vista or theough a software? Vista file management


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46