mirror of https://github.com/icsharpcode/ILSpy.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
808 B
33 lines
808 B
using System; |
|
using System.Collections.Generic; |
|
using System.Linq; |
|
using System.Linq.Expressions; |
|
using System.Text; |
|
using System.Threading.Tasks; |
|
|
|
namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness |
|
{ |
|
class ExpressionTrees |
|
{ |
|
static void Main() |
|
{ |
|
Test(); |
|
var twice = GetExpression(Expression.Constant(2)).Compile(); |
|
Console.WriteLine(twice(21)); |
|
} |
|
|
|
static void Test() |
|
{ |
|
int i = 0; |
|
Expression<Func<int>> expression = () => i; |
|
i = 1; |
|
Console.WriteLine(expression.Compile()()); |
|
} |
|
|
|
static Expression<Func<int, int>> GetExpression(Expression factor) |
|
{ |
|
ParameterExpression parameterExpression = Expression.Parameter(typeof(int), "x"); |
|
return Expression.Lambda<Func<int, int>>(Expression.Multiply(parameterExpression, factor), parameterExpression); |
|
} |
|
} |
|
}
|
|
|