tags:

views:

66

answers:

1

Please bear with me; I am very new to expression trees and lambda expressions, but trying to learn. This is something that I solved using reflection, but would like to see how to do it using expression trees.

I have a generic function:

private void DoSomeThing<T>( param object[] args ) {
    // Some work is done here.
}

that I need to call from else where in my class. Now, normally, this would be be simple:

DoSomeThing<int>( blah );

but only if I know, at design time that I am working with an int. When I do not know the type until runtime is where I need the help. Like I said, I know how to do it via reflection, but I would like to do it via expression trees, as my (very limited) understanding is that I can do so.

Any suggestions or points to sites where I can get this understanding, preferably with sample code?

+1  A: 

MethodInfo.MakeGenericMethod

Then just create a delegate and call it. (not in an expression, of course ;p)

Update:

Generally, I prefer to use generic types for this, Activator.CreateInstance just requires less work. All depends on your situation though.

leppie
As I stated, I know how to do it via reflection. I am attempting to do in via expression trees.
David Williams
Just the same, isn't it? Am I missing something? (Updated answer)
leppie