Is it possible to check the .NET Attibute setting?
I am wondering if it is possible to check the options for (custom) .net attributes. eg: If I had an attribute that takes a positive integer, can I get a compile-time error when I feed in a negative value?
[DonkeyAttribute (1)] // OK
[DonkeyAttribute (-828)] // error
For this example I could use an unsigned integer (but is it not cls-compliant I beleive?) Recommendations?
source to share
I don't think this is ok, however this article describes a solution using PostSharp . Not sure if it suits your purpose, but give it away!
source to share
You can apply this with unit tests; a similar solution to the one I suggested for this question is possible.
source to share
Directly? Not. Without rewriting csc or vbc. Most people have done this check at runtime.
However, a bit of Googling came up with this PostSharp Aspects blog post . This is not technically proven with the compiler, but it does provide a compile-time check. You can check it out here . More notes on PostSharp from the same author can be found here .
source to share