![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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 Specs![]() |
| | #3 (permalink) |
| | 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 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 Specs![]() |
| | #4 (permalink) |
| | 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 Specs![]() |
| | #5 (permalink) |
| | 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 Specs![]() |
![]() |
| 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 | |||