private void SimplifyConstants(List <Operand> operands, OperationType operationType) { var constants = operands.Where(x => x.Type == OperandType.Constant).ToList(); if (constants.Count >= 2) { var newOperand = new Operand { Type = OperandType.Constant, Value = constants[0].Value }; for (var i = constants.Count - 1; i > 0; i--) { newOperand.Value = operationType.Operation( newOperand.Value.Value, constants[i].Value.Value); } operands.RemoveAll(x => x.Type == OperandType.Constant); operands.Add(newOperand); } }