/// <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>
 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.");
     }
 }
 /// <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>
 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.");
     }
 }
示例#3
0
 public OperationPair(double x, int weight, CalculationPair calcPair) :
     base(x)
 {
     Weight   = weight;
     CalcPair = calcPair;
 }
 public CalculatorCalculation(CalculationPair calculation, int weight)
 {
     PairCalc = calculation;
     Weight   = weight;
 }
 /// <summary>
 /// Holds the weight and CalculationPair for an operation.
 /// <para>Also take a string for when a character must be escaped to be used in a regex.</para>
 /// </summary>
 /// <param name="calculationPair">Method that takes two doubles and outputs a double.</param>
 /// <param name="weight">Weight of this operation.</param>
 /// <param name="regexCharacter">String for when a character must be escaped to be used in a regex.</param>
 public CalculatorOperation(CalculationPair calculationPair, int weight, string regexCharacter)
 {
     CalculationPair = calculationPair;
     Weight          = weight;
     RegexCharacter  = regexCharacter;
 }
 /// <summary>Holds the weight and CalculationPair for an operation.</summary>
 /// <param name="calculationPair">Method that takes two doubles and outputs a double.</param>
 /// <param name="weight">Weight of this operation.</param>
 public CalculatorOperation(CalculationPair calculationPair, int weight)
 {
     CalculationPair = calculationPair;
     Weight          = weight;
     RegexCharacter  = null;
 }