c# - Calling a Generic Method using Lambda Expressions (and a Type only known at runtime) -


You can use to represent lambda as an expression.

If you call a generic method, if you only know the type that you use for the signature of the general method - at runtime?

For example:

I want to make one to call: public static TOSOS final & lt; TSource & gt; (This is IEnumerable & lt; TSource & gt; source)

But I only know that the TSource is on the runtime.

  static expression & lt; Func & lt; IEnumerable & lt; T & gt;, T & gt; & Gt; CreateLimba & lt; T & gt; () {Var source = expression.epameter (typef (IEnumerable & lt; T & gt;), "source"); Var call = expression.col (typef (enfrumer), "last", new type [] {typef (t)}, source); Return Expression Lambda & lt; Func & lt; IEnumerable & lt; T & gt;, T & gt; & Gt; (Call, source)}  

or

  Fixed LambdaExpression CreateLambda (type type) {Var source = expression.Pameter (typef (IEnumerable & lt; Gt;). MakeGenericType (type), "source"); Var call = expression.col (typef (enfollow), "last", new type [] {type}, source); Return expression. Lambda (call, source)}  

Comments