views:

33

answers:

1

I Have a few lines of code

public void CreateMethod<TContract>(Expression<Action<TContract>> method)
{
   var innerMethod = Builder.DefineMethod("SomeName",MethodAttributes.Private);
   method.CompileToMethod(innerMethod);
   //more code
}

However the second line fails. I've tried with different versions of DefineMethod with little luck. Any suggestions?

+1  A: 

Unfortunately, CompileToMethod requires a static method as its argument (see here). Therefore, you need to add MethodAttributes.Static to innerMethod's definition.

kvb
Thank you that fixed it
Rune FS
As further comments it's worth noting that you cannot pass an argument of the type the the method is compiled into
Rune FS