You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.4 KiB

  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. namespace Net3_Proxy
  7. {
  8. internal static class Utils
  9. {
  10. public static bool IsNullOrWhiteSpace(string value)
  11. {
  12. if (value == null)
  13. {
  14. return true;
  15. }
  16. for (int i = 0; i < value.Length; i++)
  17. {
  18. if (!char.IsWhiteSpace(value[i]))
  19. {
  20. return false;
  21. }
  22. }
  23. return true;
  24. }
  25. public static IEnumerable<T> Prepend<T>(this IEnumerable<T> seq, T prep)
  26. => new PrependEnumerable<T>(seq, prep);
  27. private sealed class PrependEnumerable<T> : IEnumerable<T>
  28. {
  29. private readonly IEnumerable<T> rest;
  30. private readonly T first;
  31. public PrependEnumerable(IEnumerable<T> rest, T first)
  32. {
  33. this.rest = rest;
  34. this.first = first;
  35. }
  36. public IEnumerator<T> GetEnumerator()
  37. { // TODO: a custom impl that is less garbage
  38. yield return first;
  39. foreach (var v in rest) yield return v;
  40. }
  41. IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
  42. }
  43. }
  44. }