StringMathCalculator/Calculator.cs
/// <summary>
/// Add a custom operation for the sum of two numbers. 
/// <para>Takes a regex escape string if the character must be escaped to be in a regex.</para>
/// </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 word tied to the operation. Can't contain spaces.</param>
/// <exception cref="ArgumentException">
/// Throws if the word is already in use, has spaces or is just a number.
/// </exception>
Add a custom operation for the sum of two numbers.
Takes a regex escape string if the character must be escaped to be in a regex.
Add a custom operation for the sum of two numbers . Takes a regex escape string if the character must be escaped to be in a regex .
public void AddOperation(CalculationPair calculation, uint weight, string word)
        {
            if(int.TryParse(word, out _))
            {
                throw new ArgumentException("Word can contain numbers, but must not be just a number.");
            }
            if(removeSpaces.IsMatch(word))
            {
                throw new ArgumentException("Word cannot have spaces.");
            }
            if (!wordReplacements.ContainsValue(word))
            {
                var character = AddUnusedCharacter(word);
                singleCharOperations.Add(character, new CalculatorOperation(calculation, checked((int)weight)));
                legalCharacters.Append(character);
            }
            else
            {
                throw new ArgumentException("Word is already in use for another operation.");
            }
        }
public void AddOperation ( CalculationPair calculation , uint weight , string word ) { if ( int . TryParse ( word , out _ ) ) { throw new ArgumentException ( " " ) ; } if ( removeSpaces . IsMatch ( word ) ) { throw new ArgumentException ( " " ) ; } if ( ! wordReplacements . ContainsValue ( word ) ) { var character = AddUnusedCharacter ( word ) ; singleCharOperations . Add ( character , new CalculatorOperation ( calculation , checked ( ( int ) weight ) ) ) ; legalCharacters . Append ( character ) ; } 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 if the word is already in use, has spaces or is just a number.
Throws if the word is already in use has spaces or is just 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 .
word
string
character
The word tied to the operation. Can't contain spaces.
The word tied to the operation . Can ' t contain spaces .