I would like to solve the problem of method parameter verfication in order to
avoid to writing repetitive code to validate method parameters, for example:
void method(object param)
{
if (param = null)
{
throw new ArgumentNullException("param");
}
}
and do it throw attibutes that decorate the mothods. but the I don't want
the preformance hit associated with reflection especially when it's
associated with each method invocation.
Is it possible to some how make the complire produce the code by reading the
attributes? Is it possible to extend the compiler some how? I remeber reading
something about extending the compiler in MSDN but i can't find it. is this
doable?
Greg Young - 10 May 2006 06:00 GMT
Is this what you were looking at from microsoft?
http://research.microsoft.com/research/pubs/view.aspx?msr_tr_id=MSR-TR-2003-32
There is also an extensible commercial compiler XC#
http://www.resolvecorp.com/ which might suit your needs; in fact they have
an example of almost exactly what you are trying to do here
http://www.resolvecorp.com/products.aspx
Cheers,
Greg Young
MVP - C#
>I would like to solve the problem of method parameter verfication in order
>to
[quoted text clipped - 20 lines]
> this
> doable?
eacsub - 10 May 2006 14:25 GMT
Thank you Greg. Although, I don't think I wan't to substitute microsoft
compiler for a third party compiler and I don't want to create my own
compiler. Is there a middle way where i can intercept the compilation process
so that I read the attributes and convert them into code in the message body
and compile that code and produce the final assembly. maybe:
- compile into assembly with the attributes
- load the assembly, read the attributes and produce the code in the method
body
- compile the final code and generate the final assemble that has the
assertions.
> Is this what you were looking at from microsoft?
> http://research.microsoft.com/research/pubs/view.aspx?msr_tr_id=MSR-TR-2003-32
[quoted text clipped - 32 lines]
> > this
> > doable?
Greg Young - 10 May 2006 20:22 GMT
Not that I know of .. but there are many people around here who are alot
wiser than I.
Cheers,
Greg Young
MVP - C#
> Thank you Greg. Although, I don't think I wan't to substitute microsoft
> compiler for a third party compiler and I don't want to create my own
[quoted text clipped - 51 lines]
>> > this
>> > doable?
Jay B. Harlow [MVP - Outlook] - 11 May 2006 01:46 GMT
eacsub,
Refactor! & other refactoring tools have a "Create Method Contract"
refactoring that adds the checks for you.
Refactor! does a return rather then throw an exception, haven't used it
enough to know if that is configurable or not. Using DXCore (the *free*
runtime that Refactor! is based on) would allow you to create your own
"add-in" for VS that injects the code you want...

Signature
Hope this helps
Jay B. Harlow [MVP - Outlook]
.NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
|I would like to solve the problem of method parameter verfication in order to
| avoid to writing repetitive code to validate method parameters, for example:
[quoted text clipped - 15 lines]
| something about extending the compiler in MSDN but i can't find it. is this
| doable?