AbstractCombiner.cs 638 B

123456789101112131415161718192021
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. namespace InABox.Mobile
  5. {
  6. public abstract class AbstractCombiner<TValue,TFunction> : AbstractMultiConverter<TValue,TValue>
  7. where TFunction : struct, IConvertible
  8. {
  9. public TFunction Function { get; set; }
  10. protected abstract TValue Combine(TValue current, TValue next);
  11. protected override TValue Convert(IEnumerable<TValue> value, object parameter = null)
  12. {
  13. if (value?.Any() != true)
  14. return default;
  15. return value.Aggregate<TValue,TValue>(default,Combine);
  16. }
  17. }
  18. }