CollectionUtilities.cs 1.5 KB

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