public Argument Evaluate() { if (!Arguments[0].CanEvaluate || !Arguments[2].CanEvaluate) { throw new CodeblockOperatorException("The codeblock arguments can not be empty."); } object l = Arguments[0].Evaluateble.Evaluate().Value; object r = Arguments[2].Evaluateble.Evaluate().Value; // Get the types of the arguments ArgumentType lType = ArgumentTypeHelper.FromObject(l); ArgumentType rType = ArgumentTypeHelper.FromObject(r); // Ensure the arguments don't have different types if (lType != rType) { throw new CodeblockOperatorException("The codeblock arguments must have the same type."); } // Use the left argument to see which type the comparison should take IComparisonTypeOperator comparisonOperator; ComparisonOperator operation = (ComparisonOperator)Arguments[1].Evaluateble.Evaluate().Value; switch (lType) { case ArgumentType.Number: comparisonOperator = new NumberOperator(); break; case ArgumentType.String: comparisonOperator = new StringOperator(); break; case ArgumentType.Boolean: comparisonOperator = new BooleanOperator(); break; default: throw new CodeblockOperatorException($"No valid operator found for argument type {lType}."); } object result = EvaluateOperation(l, r, comparisonOperator, operation); return(new Argument(result, ResultingType)); }
public Argument(object value) { Value = value; Type = ArgumentTypeHelper.FromObject(value); }
public Argument Evaluate() => new Argument(_content, ArgumentTypeHelper.FromObject(_content));