Last active
October 23, 2017 06:55
-
-
Save ZhangSen1/adaaedd8ce358122358e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MethodInfo method = typeof(string).GetMethod("StartsWith", new[] { typeof(string) }); | |
var target = Expression.Parameter(typeof (string), "x"); | |
var methodArg = Expression.Parameter(typeof (string), "y"); | |
Expression[] methodArgs = new[] { methodArg }; | |
Expression call = Expression.Call(target, method, methodArgs); | |
var lambdaParameters = new[] {target, methodArg}; | |
var lambda = Expression.Lambda<Func<string, string, bool>>(call, lambdaParameters); | |
var lc = lambda.Compile(); | |
Console.WriteLine(lc("first", "ss")); | |
Expression<Func<string, string, bool>> lambda1 = (s, s1) => s.StartsWith(s1); | |
var lc1 = lambda1.Compile(); | |
Console.WriteLine(lc1("34","3")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment