Expression<Func<int, int, int>> addition = (a, b) => a + b;
Console.WriteLine($"This expression is a {addition.NodeType} expression type");
Console.WriteLine($"The name of the lambda is {((addition.Name == null) ? "<null>" : addition.Name)}");
Console.WriteLine($"The return type is {addition.ReturnType.ToString()}");
Console.WriteLine($"The expression has {addition.Parameters.Count} arguments. They are:");
foreach (var argumentExpression in addition.Parameters)
{
Console.WriteLine($"\tParameter Type: {argumentExpression.Type.ToString()}, Name: {argumentExpression.Name}");
}
var additionBody = (BinaryExpression)addition.Body;
Console.WriteLine($"The body is a {additionBody.NodeType} expression");
Console.WriteLine($"The left side is a {additionBody.Left.NodeType} expression");
var left = (ParameterExpression)additionBody.Left;
Console.WriteLine($"\tParameter Type: {left.Type.ToString()}, Name: {left.Name}");
Console.WriteLine($"The right side is a {additionBody.Right.NodeType} expression");
var right = (ParameterExpression)additionBody.Right;
Console.WriteLine($"\tParameter Type: {right.Type.ToString()}, Name: {right.Name}");
publicclass TestMonths
{
publicint Conver32(int a)
{
return Convert.ToInt32(a);
}
}
TestMonths testMonths = new TestMonths();
var gg = 99;
Expression<Func<UserInfo, int, int, double>> exception = (user, a, b) => user.Age + (a / b) * a - b + a - (b + b) + (a % b) + (a > b ? a : b) / user.Level * gg + testMonths.Conver32(user.Level);
LambdaVisitor visitor = new LambdaVisitor(exception);
visitor.Visit("解析二进制运算:");
Console.WriteLine("\t");
demo2:
Expression<Func<UserInfo, UserInfoModel>> lambda = (user) => new UserInfoModel
{
Age = user.Age,
Level = EF.Functions.DataLength(user.Name) ?? 0,
Name = user.Name
};
LambdaVisitor visitor3 = new LambdaVisitor(lambda);
visitor3.Visit("解析查询表达式:");