public static Call ( |
||
instance | An |
|
method | The |
|
return |
// Create an Expression object for Math.Max(int, int) Expression callExpr = Expression.Call( typeof(Math), "Max", null, new[] { Expression.Constant(4), Expression.Constant(7) }); // Compile the expression and invoke the method int result = (int)Expression.Lambda(callExpr).Compile().DynamicInvoke();
// Create an instance of the String class string str = "Hello World"; // Create an Expression object for str.Contains("World") Expression callExpr = Expression.Call( Expression.Constant(str), typeof(string).GetMethod("Contains"), new[] { Expression.Constant("World") }); // Compile the expression and invoke the method bool result = (bool)Expression.Lambda(callExpr).Compile().DynamicInvoke();In this example, we create an Expression object that represents a call to the instance method String.Contains with a single string argument. We then compile the expression and invoke the method using DynamicInvoke. Package library: System.Core.
public static Call ( |
||
instance | An |
|
method | The |
|
return |