ExtenstionMetohd.cs 662 B

12345678910111213141516171819202122
  1. namespace FNZCM.BlazorWasm.Helpers
  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 T[] KeepNoEmpty<T>(this T[] source)
  15. {
  16. if (false == (source?.Length > 0)) return new T[1];
  17. return source;
  18. }
  19. }
  20. }