CollectionUtilities.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using System.Collections;
  5. #if UNITY_WSA && !UNITY_EDITOR && !ENABLE_IL2CPP
  6. using System.TypeFix;
  7. #endif
  8. using System.Text;
  9. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Collections
  10. {
  11. public abstract class CollectionUtilities
  12. {
  13. public static void AddRange(IList to, IEnumerable range)
  14. {
  15. foreach (object o in range)
  16. {
  17. to.Add(o);
  18. }
  19. }
  20. public static bool CheckElementsAreOfType(IEnumerable e, Type t)
  21. {
  22. foreach (object o in e)
  23. {
  24. if (!t.IsInstanceOfType(o))
  25. return false;
  26. }
  27. return true;
  28. }
  29. public static IDictionary ReadOnly(IDictionary d)
  30. {
  31. return new UnmodifiableDictionaryProxy(d);
  32. }
  33. public static IList ReadOnly(IList l)
  34. {
  35. return new UnmodifiableListProxy(l);
  36. }
  37. public static ISet ReadOnly(ISet s)
  38. {
  39. return new UnmodifiableSetProxy(s);
  40. }
  41. public static object RequireNext(IEnumerator e)
  42. {
  43. if (!e.MoveNext())
  44. throw new InvalidOperationException();
  45. return e.Current;
  46. }
  47. public static string ToString(IEnumerable c)
  48. {
  49. IEnumerator e = c.GetEnumerator();
  50. if (!e.MoveNext())
  51. return "[]";
  52. StringBuilder sb = new StringBuilder("[");
  53. sb.Append(e.Current.ToString());
  54. while (e.MoveNext())
  55. {
  56. sb.Append(", ");
  57. sb.Append(e.Current.ToString());
  58. }
  59. sb.Append(']');
  60. return sb.ToString();
  61. }
  62. }
  63. }
  64. #pragma warning restore
  65. #endif