StringCalculator.cs 1.2 KB

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