Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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 ?

  • Leaders
Posted

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.

[sIGPIC]e[/sIGPIC]
Posted

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...