Way to create a customized compiler side-effect Attribute ?

docflied

Newcomer
Joined
Nov 28, 2009
Messages
17
Hi everybody.
I was wondering if any one had encoutered the need to create a custom .net attribute that acts like ObsoleteAttribute ?

So lets suppose that this attribut is coded and is called MySpecialAttribute and lets say that its targeted for Methods only.

What I need is that at the moment the coder will declare a sush attribute and while he is in IDE mode (visual studio only or other compiliant IDE) a special job is done with possible forced compiling error ?
Example :
<MySpecialAttribute()> _
Public Sub MyMethodToBeControled(ByVal Param1 As Object)
...
End Sub

In this case I want to check that arguments of the Sub MyMethodToBeControled meet some conditions (type or name) and if not raise a compiling error in the IDE like ObsoleteAttribut does.

Any Idea from experts ?
 
You most-certainly can create custom attributes (Creating and Using Custom Attributes with VB.NET), but they can not execute any code. They are not even instantiated until you explicitly retrieve the attribute at runtime.

You can create your own post-build process that does reflection on the compiled code and reports problems (or a pre-build process that examines the original code). Or maybe a script or an add-on... I don't know.
 
So in other words the ObsoleteAttribute behavior is quiet special and cannot be imitated?

I thought there is some interface or class in a dedicated compiler services or dedicated visual studio assembly (dont know if it exists) that I would implement or inherit to create a "while-coding" side effect custom attribute, as ObsoleteAttribute does.

Thank u for ur help.
 
Back
Top