StringCalculator.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using System.Collections.Generic;
  2. using System.ComponentModel;
  3. using System.Linq;
  4. namespace InABox.WPF
  5. {
  6. // public class StringCalculator : AbstractCalculator<string, StringCombinerFunction>
  7. // {
  8. //
  9. // public string Separator { get; set; }
  10. // protected override string Combine(string current, string next)
  11. // {
  12. // return Function switch
  13. // {
  14. // StringCombinerFunction.Append => string.Join(Separator, new [] { current, next } ),
  15. // _ => current
  16. // };
  17. // }
  18. // }
  19. public class StringCalculatorFunction : AbstractCalculatorFunction<string, StringCalculatorType>
  20. {
  21. public string Separator { get; set; }
  22. protected override string Calculate(string current, string next, StringCalculatorType type)
  23. {
  24. var result = type switch
  25. {
  26. StringCalculatorType.Append => string.Join(Separator, new [] { current, next } ),
  27. _ => current
  28. };
  29. return result;
  30. }
  31. }
  32. public class StringCalculator : AbstractCalculator<string, StringCalculatorFunction, StringCalculatorType>
  33. {
  34. public string Separator
  35. {
  36. get => Function.Separator;
  37. set => Function.Separator = value;
  38. }
  39. }
  40. }