Girish said:
If I have something like that
class TestNegativeValue:Attribute
{
// ...
}
...
[TestNegativeValue]
public void ExceptionNegativeValue(int i)
{
//...
}
how can I test i(throw exception if i<0) directly
from the attribute body ?
You cannot in normal circumstances.
You can implement a ContextAttribute on a ContextBoundObject, which will
allow you to analyze the messages entering and exiting a contexual object,
but it is extremely expensive for what you are doing, fairly difficult, and
has a questionable future life. I also don't know for sure how exceptions
work with it. I would avoid that if at all possible.
Another option is a product, with free and commercial versions you'll have
to evaluate yourself, XC#[1], which allows authors to write attributes to
modify and declare constraints using attributes. However, while the code
written for this compiler will compile correctly on any other C# compiler,
the attributes and constraints will only work on the XC# compiler and any
compiler which implements its functionality(which the MS and Mono C#
compilers do not currently do).
1.
http://www.resolvecorp.com/