• After more than 30 years running websites and forums I am retiring.

    I have made many friends through the years. I will cherish my time getting to know you. I wish you all the best. This was not an easy decision to make. The cost to keep the communities running has gotten to the point where it's just too expensive. Security certificates, hosting cost, software renewals and everything else has increased threefold. While costs are up ad revenue is down. It's no longer viable to keep things running.

    All sites will be turned off on Thursday 30 November 2023. If you are interested in acquiring any of the websites I own you can Email Schwarz Network.

Way to create a customized compiler side-effect Attribute ?

docflied

Newcomer
Joined
Nov 28, 2009
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 ?
 

snarfblam

Ultimate Contributor
Joined
Jun 10, 2003
Location
USA
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.
 

docflied

Newcomer
Joined
Nov 28, 2009
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.
 
Top Bottom