private Expression TryRegisterSuffixFunc(BinaryExpression node) { if (node.NodeType != ExpressionType.Assign) { return(null); } var left = node.Left as ParameterExpression; if (left == null) { return(null); } var right = node.Right as NewExpression; if (right == null || right.Arguments.Count == 0) { return(null); } var sfxFuncType = right.Constructor.DeclaringType; if (typeof(SuffixFunc <>) != sfxFuncType.GetGenericTypeDefinition()) { return(null); } //if ((right.Arguments[0] is LambdaExpression) == false) // return null; var funcType = sfxFuncType.GetGenericArguments()[0]; var suffix = ((ConstantExpression)right.Arguments[1]).Value as string[]; var param = Expression.Parameter(funcType, left.Name + "_Body"); var info = new SuffixFuncInfo { Suffix = suffix, FuncExpr = param }; _dic[left] = info; var body = this.Visit(right.Arguments[0]) as LambdaExpression; if (info.IsUsed) { body = Expression.Lambda(body.Body, true, body.Parameters); } return(Expression.Assign(left, Expression.New(right.Constructor, Expression.Assign(param, body), right.Arguments[1]))); }
private Expression TryRegisterSuffixFunc(BinaryExpression node) { if (node.NodeType != ExpressionType.Assign) return null; var left = node.Left as ParameterExpression; if (left == null) return null; var right = node.Right as NewExpression; if (right == null || right.Arguments.Count == 0) return null; var sfxFuncType = right.Constructor.DeclaringType; if (typeof(SuffixFunc<>) != sfxFuncType.GetGenericTypeDefinition()) return null; //if ((right.Arguments[0] is LambdaExpression) == false) // return null; var funcType = sfxFuncType.GetGenericArguments()[0]; var suffix = ((ConstantExpression)right.Arguments[1]).Value as string[]; var param = Expression.Parameter(funcType, left.Name + "_Body"); var info = new SuffixFuncInfo { Suffix = suffix, FuncExpr = param }; _dic[left] = info; var body = this.Visit(right.Arguments[0]) as LambdaExpression; if (info.IsUsed) body = Expression.Lambda(body.Body, true, body.Parameters); return Expression.Assign(left, Expression.New(right.Constructor, Expression.Assign(param, body), right.Arguments[1])); }