ExtenstionMetohd.cs 737 B

1234567891011121314151617181920212223
  1. namespace FNZCM.BlazorWasm.Utility
  2. {
  3. public static class ExtenstionMetohd
  4. {
  5. public static IEnumerable<(T item, int index)> WithIndex<T>(this IEnumerable<T> self)
  6. => self.Select((item, index) => (item, index));
  7. public static TV GetEx<TK, TV>(this IDictionary<TK, TV> dic, TK key)
  8. {
  9. if (key == null) return default;
  10. return dic.TryGetValue(key, out var tv)
  11. ? tv
  12. : default;
  13. }
  14. public static IReadOnlyCollection<T> KeepNoEmpty<T>(this IReadOnlyCollection<T> source)
  15. {
  16. if (source == null) return new T[1];
  17. if (source.Count == 0) return new T[1];
  18. return source;
  19. }
  20. }
  21. }