StringMathCalculator/Calculator.cs
/// <summary>
/// Add a custom operation for the sum of two numbers.
/// </summary>
/// <param name="calculation">The method that takes two doubles and returns a double.</param>
/// <param name="weight">The weight of the operation.</param>
/// <param name="character">The character tied to the operation.</param>
/// <exception cref="ArgumentException">
/// Throws when a reserved charcter of '(', ')' or '.' is used, if the character is already in use or the character is a number.
/// </exception>
Add a custom operation for the sum of two numbers.
Add a custom operation for the sum of two numbers .
public void AddOperation(CalculationPair calculation, uint weight, char character)
        {
            if (int.TryParse(character.ToString(), out _))
            {
                throw new ArgumentException("Character cannot be a number.");
            }
            if (reservedChars.Contains(character))
            {
                throw new ArgumentException("Reserved character, please avoid '(', ')' and '.'");
            }
            if (!singleCharOperations.ContainsKey(character))
            {
                singleCharOperations.Add(character, new CalculatorOperation(calculation, checked((int)weight)));
                if (character != '\\')
                {
                    legalCharacters.Append(character);
                }
                else
                {
                    legalCharacters.Append(@"\\");
                }
            }
            else if(WordReplacementsContains(character))
            {
                singleCharOperations.Add(character, new CalculatorOperation(calculation, checked((int)weight)));
            }
            else
            {
                throw new ArgumentException("Character is already in use for another operation.");
            }
        }
public void AddOperation ( CalculationPair calculation , uint weight , char character ) { if ( int . TryParse ( character . ToString ( ) , out _ ) ) { throw new ArgumentException ( " " ) ; } if ( reservedChars . Contains ( character ) ) { throw new ArgumentException ( " " ) ; } if ( ! singleCharOperations . ContainsKey ( character ) ) { singleCharOperations . Add ( character , new CalculatorOperation ( calculation , checked ( ( int ) weight ) ) ) ; if ( character != ' \\ ' ) { legalCharacters . Append ( character ) ; } else { legalCharacters . Append ( @"\\" ) ; } } else if ( WordReplacementsContains ( character ) ) { singleCharOperations . Add ( character , new CalculatorOperation ( calculation , checked ( ( int ) weight ) ) ) ; } else { throw new ArgumentException ( " " ) ; } }
Add a custom operation for the sum of two numbers.
Add a custom operation for the sum of two numbers .
Throws when a reserved charcter of '(', ')' or '.' is used, if the character is already in use or the character is a number.
Throws when a reserved charcter of ' ( ' ' ) ' or ' . ' is used if the character is already in use or the character is a number .
calculation
CalculationPair
The method that takes two doubles and returns a double.
The method that takes two doubles and returns a double .
weight
uint
The weight of the operation.
The weight of the operation .
character
char
The character tied to the operation.
The character tied to the operation .