Reflection Generated Generic Lambda Expression RRS feed

  • Question

  • SO,

    I've looked around and wondered if this was possible.  I've seen many different solutions for the same problem so please don't give me them, answer this one:

    T MyFunc<T> { return default(T); }

    I want to convert that into a Expression.Lambda();

    So I can provide the value of the T parameter at creation.   I know I will have to recreate the expression, the same as doing a MakeGenericMethod() call, but I can't seem to find out how to enact the "default(T)" part of the Expression.  I can use reflection for the Method and return type, but default is a key word, and so far I can find a reference to the type parameter in the Expression.* static methods.

    (Like I said there are other ways using Activator.CreatInstance() to do this, but I am curious and would like to know if this could be done)


    Jaeden "Sifo Dyas" al'Raec Ruiner

    "Never Trust a computer. Your brain is smarter than any micro-chip."
    PS - Don't mark answers on other people's questions. There are such things as Vacations and Holidays which may reduce timely activity, and until the person asking the question can test your answer, it is not correct just because you think it is. Marking it correct for them often stops other people from even reading the question and possibly providing the real "correct" answer.

    Friday, May 15, 2015 3:15 PM

All replies

  • Don't you think you can better use direct JavaScript. 

    C# is a program language around strongly types, not for late binding programming.


    Friday, May 15, 2015 3:37 PM