public Expression ToExpression(ParseContext context) { switch (AssignType) { case (AssignementOperator.Assign): { //if (RValue.ParsedType.IsValueType) { return(Expression.Assign(LValue.ToExpression(context), Expression.Convert(RValue.ToExpression(context), LValue.ParsedType))); } //return Expression.Assign(LValue.ToExpression(context), RValue.ToExpression(context)); } case (AssignementOperator.MultiplyAssign): return(Expression.MultiplyAssign(LValue.ToExpression(context), RValue.ToExpression(context))); case (AssignementOperator.SubtractAssign): return(Expression.SubtractAssign(LValue.ToExpression(context), RValue.ToExpression(context))); case (AssignementOperator.SumAssign): { if (LValue.ParsedType == typeof(string) || RValue.ParsedType == typeof(string)) { Expression <Func <object, object, string> > func = ((a, b) => SumAssign(a, b)); return(Expression.Assign(LValue.ToExpression(context), Expression.Invoke(func, LValue.ToExpression(context), RValue.ToExpression(context)))); } return(Expression.AddAssign(LValue.ToExpression(context), RValue.ToExpression(context))); } } throw new InvalidEnumArgumentException(); }
public Expression ToExpression(ParseContext context) { var collectionVarExpr = CollectionSourceVar.ToExpression(context); //CollectionExpr context.AddLevel(); //Type itemType = CollectionSourceVar.ParsedType.GetGenericArguments().Single(); var item = LoopVar.ToExpression(context) as ParameterExpression; var loopContent = new List <Expression>(); foreach (var line in CodeLines) { var expLine = line.ToExpression(context); var createVariable = line as CreateVariable; if (createVariable != null) { //listOfThenVars.Add((ParameterExpression)expLine); expLine = createVariable.DefaultInitialize(context); } loopContent.Add(expLine); } return(ForEachExpr(collectionVarExpr, item, loopContent.ToArray(), context)); }