compile-time error generating custom attributes

P

Picho

hi all,

can I create my own compile-time attributes?
e.g. an attribute applied to a method and that will generate a compile time
error if the method has the wrong signature?

I was hinted twords 'Intellisense API' but cant seem to find it at all...


thanx,
Picho
 
G

Gaurav Vaish \(www.EduJini.IN\)

New/Custom attributes that you created would not be understood by Visual
Studio / Compiler..

Specific to your case, where do you wish to apply this attribute -- checking
the method signature?
 
P

Picho

thanx for the reply.

I would like to avoid run-time errors caused by objects that apply my
attributes to their class members.

I could have used simply interfaces but I need more info on the members such
as descriptions, and other things.

plus I wish to avoid the need of implementing my interface AND applying
attributes.

when I apply an attribute that is defined to target a method to a property,
i get a compilation error right?

cant I extend this and create attributes that will validate certains
constrains and produce compile-time errors?
 
B

Ben Voigt

Picho said:
thanx for the reply.

I would like to avoid run-time errors caused by objects that apply my
attributes to their class members.

I could have used simply interfaces but I need more info on the members
such as descriptions, and other things.

plus I wish to avoid the need of implementing my interface AND applying
attributes.

You probably do want both... method calls through interfaces are many times
faster than reflection on attributes and a reflected call.
 
G

Gaurav Vaish \(www.EduJini.IN\)

I could have used simply interfaces but I need more info on the members
such as descriptions, and other things.

Define interfaces.
Define attributes.... do both.

The implementation class can be discovered dynamically using reflection (say
from config files).
Use the reference to the implementation for all uses. Whenever required,
reflect on the class to find attribute values.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top