using System;
using System.Linq.Expressions;
namespace TestBench
{
class Program
{
static void Main(string[] args)
{
ParameterExpression innerX = Expression.Parameter(typeof(int), "innerX");
ParameterExpression outerX = Expression.Parameter(typeof(int), "outerX");
//outerXとinnerXでInvokeを介してParameterの読み替えが起きている。
var expression = Expression.Lambda<Func<int, int>>(
Expression.Invoke(Expression.Lambda<Func<int, int>>(
Expression.Add(innerX, innerX), innerX), outerX), outerX);
Console.WriteLine(expression.Compile()(10));
}
}
}
dXNpbmcgU3lzdGVtOwp1c2luZyBTeXN0ZW0uTGlucS5FeHByZXNzaW9uczsKCgpuYW1lc3BhY2UgVGVzdEJlbmNoCnsKCWNsYXNzIFByb2dyYW0KCXsKCQlzdGF0aWMgdm9pZCBNYWluKHN0cmluZ1tdIGFyZ3MpCgkJewoJCQlQYXJhbWV0ZXJFeHByZXNzaW9uIGlubmVyWCA9IEV4cHJlc3Npb24uUGFyYW1ldGVyKHR5cGVvZihpbnQpLCAiaW5uZXJYIik7CgkJCVBhcmFtZXRlckV4cHJlc3Npb24gb3V0ZXJYID0gRXhwcmVzc2lvbi5QYXJhbWV0ZXIodHlwZW9mKGludCksICJvdXRlclgiKTsKCgkJCS8vb3V0ZXJY44GoaW5uZXJY44GnSW52b2tl44KS5LuL44GX44GmUGFyYW1ldGVy44Gu6Kqt44G/5pu/44GI44GM6LW344GN44Gm44GE44KL44CCCgkJCXZhciBleHByZXNzaW9uID0gRXhwcmVzc2lvbi5MYW1iZGE8RnVuYzxpbnQsIGludD4+KAoJCQkJRXhwcmVzc2lvbi5JbnZva2UoRXhwcmVzc2lvbi5MYW1iZGE8RnVuYzxpbnQsIGludD4+KAoJCQkJRXhwcmVzc2lvbi5BZGQoaW5uZXJYLCBpbm5lclgpLCBpbm5lclgpLCBvdXRlclgpLCBvdXRlclgpOwoKCQkJQ29uc29sZS5Xcml0ZUxpbmUoZXhwcmVzc2lvbi5Db21waWxlKCkoMTApKTsKCgkJfQoJfQp9Cg==