ComparerGenerator.cs 732 B

123456789101112131415161718192021222324252627282930313233
  1. using System;
  2. using System.Collections.Generic;
  3. using HandyControl.Data;
  4. namespace HandyControl.Tools;
  5. public class ComparerGenerator
  6. {
  7. private static readonly Dictionary<Type, ComparerTypeCode> TypeCodeDic = new()
  8. {
  9. [typeof(DateTimeRange)] = ComparerTypeCode.DateTimeRange,
  10. };
  11. public static IComparer<T> GetComparer<T>()
  12. {
  13. if (TypeCodeDic.TryGetValue(typeof(T), out var comparerType))
  14. {
  15. if (comparerType == ComparerTypeCode.DateTimeRange)
  16. {
  17. return (IComparer<T>) new DateTimeRangeComparer();
  18. }
  19. return null;
  20. }
  21. return null;
  22. }
  23. private enum ComparerTypeCode
  24. {
  25. DateTimeRange
  26. }
  27. }