I'm starting a project to add functionality through custom attributes.
I'm tired of writing parameter validation code and tracing logic.
Besides, it sometimes obscures the real code of a method. I'd love to
express my intentions with custom attributtes, and modify the
resulting assembly after compilation
For example, the following (admitly silly) function
string Dummy(string s, object o)
{
try
{
if(s == null || s.Length == 0)
{
throw new ArgumentException("s can not be empty");
}
if(o == null)
{
throw new ArgumentNullException("o");
}
return s + o.ToString();
}
catch(Exception e)
{
Trace.TraceError(string.Format(
"Exception '{0}' on string Dummy(object o ('{1}'), string
s ('{2}'))", e, o, s));
throw;
}
}
would be much simpler as:
[TraceExceptions]
string Dummy([NotEmpty] string s, [NotNull] object o)
{
return s + o.ToString();
}
I imagine other uses (RangeAttribute, extracting documentation, maybe
even pre and postconditions).
Now, the question. Do you think Cecil should be the basis for this
project? Do you know of a more suitable approach?
Any thoughts before I sink a month on this before hitting my head with
a wall would be really appreciated.
--~--~---------~--~----~------------~-------~--~----~
--
mono-cecil
-~----------~----~----~----~------~----~------~--~---