/// <summary>
 /// Creates a new derivative operation from a menu module and one operator/double KeyValuePair for
 /// every option in the menu. The operator and double used will be based on which menu option is
 /// picked.
 /// </summary>
 /// <param name="reference">The menu module.</param>
 /// <param name="operations">The KeyValuePairs of operators and doubles.</param>
 public DerivativeOperation(ModuleMenu reference, params KeyValuePair <char, double>[] operations)
 {
     if (reference.MenuOptions.Length != operations.Length)
     {
         throw new ArgumentException("Can only make a derivative operation based on a MenuModule if there's a KeyValuePair for every option.");
     }
     this.reference = reference;
     logic          = operations[0].Key + "" + operations[0].Value;
     for (int i = 1; i < operations.Length; i++)
     {
         logic += "," + operations[i].Key + "" + operations[i].Value;
     }
 }
            /// <summary>
            /// Does this DerivativeOperation's calculation on a number.
            /// </summary>
            /// <param name="source">The original number.</param>
            /// <returns>The number after calculation.</returns>
            public double Calc(double source)
            {
                double val = source;

                if (reference == null)
                {
                    char   oper = logic[0];
                    double mod  = double.Parse(logic.Substring(1));
                    val = Operate(oper, source, mod);
                }
                else if (reference is ModuleCheck)
                {
                    ModuleCheck check  = reference as ModuleCheck;
                    string[]    logics = logic.Split(',');
                    if (check.IsChecked)
                    {
                        char   oper = logics[0][0];
                        double mod  = double.Parse(logics[0].Substring(1));
                        val = Operate(oper, source, mod);
                    }
                    else if (logics.Length > 1)
                    {
                        char   oper = logics[1][0];
                        double mod  = double.Parse(logics[1].Substring(1));
                        val = Operate(oper, source, mod);
                    }
                }
                else if (reference is ModuleMenu)
                {
                    ModuleMenu menu   = reference as ModuleMenu;
                    string[]   logics = logic.Split(',');
                    char       oper   = logics[menu.MenuIndex - 1][0];
                    double     mod    = double.Parse(logics[menu.MenuIndex - 1].Substring(1));
                    val = Operate(oper, source, mod);
                }
                else if (reference is ModuleNumeric)
                {
                    ModuleNumeric numeric = reference as ModuleNumeric;
                    char          oper    = logic[0];
                    double        mod     = numeric.Number;
                    val = Operate(oper, source, mod);
                }
                else
                {
                    throw new ArgumentException("Cannot calculate a DerivativeOperation based on a " + reference.ModuleType + " module.");
                }

                return(val);
            }