DoubleCalculator.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using System.Collections.Generic;
  2. using System.ComponentModel;
  3. using System.Linq;
  4. using System.Net.Http.Headers;
  5. namespace InABox.WPF
  6. {
  7. public class DoubleCalculatorFunction : AbstractCalculatorFunction<double, NumericCalculatorType>
  8. {
  9. protected override double Calculate(double current, double next, NumericCalculatorType type)
  10. {
  11. var result = type switch
  12. {
  13. NumericCalculatorType.Sum => current + next,
  14. NumericCalculatorType.Product => current * next,
  15. NumericCalculatorType.Subtraction => current - next,
  16. NumericCalculatorType.Maximum => current > next ? current : next,
  17. NumericCalculatorType.Minimum => current < next ? current : next,
  18. _ => current
  19. };
  20. return result;
  21. }
  22. }
  23. public class DoubleArrayConverter : AbstractNumericArrayConverter<double>
  24. {
  25. protected override double[] Convert(IEnumerable<string> values)
  26. {
  27. var result = values.Select(double.Parse).ToArray();
  28. return result;
  29. }
  30. }
  31. public class DoubleCalculator : AbstractNumericCalculator<double, DoubleCalculatorFunction>
  32. {
  33. [TypeConverter(typeof(DoubleArrayConverter))]
  34. public override double[] Constants { get; set; }
  35. }
  36. }