public static Calc SwitchSignWhenNotWait(
     this Calc calc)
 {
     return(PatternMatch.Match()
            .With(() => calc.m_sign.Equals("+") &&
                  !calc.m_input.Equals(""),
                  () => calc.SwitchSignWhenPositive())
            .Else(() => calc.SwitchSignWhenNegative())
            .Do());
 }
 public static Calc AppendNum(
     this Calc calc,
     double numValue)
 {
     return(PatternMatch.Match()
            .With(
                () => numValue == Math.Round(numValue) &&
                numValue >= 0,
                () => calc.AppendNumWhenRound(numValue))
            .Else(
                () => calc.AppendNumWhenNotRound(numValue))
            .Do());
 }
 public static Calc PrepareOperationDivide(
     this Calc calc)
 {
     return(PatternMatch.Match()
            .With(
                () => calc.m_lastNum == null ||
                calc.m_wait,
                () => calc.PrepareOperationDivideLastNumNull())
            .Else(
                () => calc.PrepareOperationDivideLastNumNonNull())
            .Do()
            .ModifyCalcLastHitEquals(false));
 }
 public static Calc DoDeleteIfValid(
     this Calc calc)
 {
     return(PatternMatch.Match()
            .With(() => calc.m_decimal == true,
                  () => calc.DeleteWithDecimal())
            .Else(() => calc.DeleteWithoutDecimal())
            .Do()
            .ModifyCalcInputWhen(
                () => calc.m_input.Equals(".") ||
                calc.m_input.Equals("-."),
                ".")
            .ModifyCalcSignWhen(
                () => calc.m_input.Equals(".") ||
                calc.m_input.Equals("-."),
                "+"));
 }
 public static Calc AppendNumWhenRound(
     this Calc calc,
     double numValue)
 {
     return(PatternMatch.Match()
            .With(
                () => calc.m_input.Equals(".") ||
                calc.m_wait == true,
                () => calc.AppendNumWhenRoundAndEmpty(
                    numValue))
            .Else(
                () => calc.AppendNumWhenRoundAndNotEmpty(
                    numValue))
            .Do()
            .ModifyCalcInputWhen(
                () => calc.m_input.IndexOf("0", 0, 1) == 0 &&
                calc.m_input.IndexOf(".") > 1,
                calc.m_input.Remove(0, 1)));
 }
 public static Calc FunctionButton(
     this Calc calc,
     string str)
 {
     return(PatternMatch.Match()
            .With(() => str == "sqrt",
                  () => calc.FunctionButtonSqrt())
            .With(() => str == "percent",
                  () => calc.FunctionButtonPercent())
            .With(() => str == "inverse",
                  () => calc.FunctionButtonInverse())
            .With(() => str == "delete",
                  () => calc.FunctionButtonDelete())
            .With(() => str == "switchSign",
                  () => calc.FunctionButtonSwitchSign())
            .With(() => str == "decimal",
                  () => calc.FunctionButtonDecimal())
            .Do());
 }
 public static Calc PrepareOperation(
     this Calc calc,
     string strOperator)
 {
     return(PatternMatch.Match()
            .With(
                () => strOperator == "add",
                () => calc.PrepareOperationAdd())
            .With(
                () => strOperator == "subtract",
                () => calc.PrepareOperationSubtract())
            .With(
                () => strOperator == "multiply",
                () => calc.PrepareOperationMultiply())
            .With(
                () => strOperator == "divide",
                () => calc.PrepareOperationDivide())
            .Do());
 }