diff options
Diffstat (limited to 'crypto/src/util/collections')
-rw-r--r-- | crypto/src/util/collections/CollectionUtilities.cs | 15 | ||||
-rw-r--r-- | crypto/src/util/collections/EnumerableProxy.cs | 25 |
2 files changed, 33 insertions, 7 deletions
diff --git a/crypto/src/util/collections/CollectionUtilities.cs b/crypto/src/util/collections/CollectionUtilities.cs index e0c79bdf4..37551e5b3 100644 --- a/crypto/src/util/collections/CollectionUtilities.cs +++ b/crypto/src/util/collections/CollectionUtilities.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Collections.Generic; using System.Text; namespace Org.BouncyCastle.Utilities.Collections @@ -14,14 +15,14 @@ namespace Org.BouncyCastle.Utilities.Collections } } - public static bool CheckElementsAreOfType(IEnumerable e, Type t) + public static IEnumerable Proxy(IEnumerable e) { - foreach (object o in e) - { - if (!t.IsInstanceOfType(o)) - return false; - } - return true; + return new EnumerableProxy(e); + } + + public static IEnumerable<T> Proxy<T>(IEnumerable<T> e) + { + return new EnumerableProxy<T>(e); } public static IDictionary ReadOnly(IDictionary d) diff --git a/crypto/src/util/collections/EnumerableProxy.cs b/crypto/src/util/collections/EnumerableProxy.cs index 9eec4af21..196b4d9df 100644 --- a/crypto/src/util/collections/EnumerableProxy.cs +++ b/crypto/src/util/collections/EnumerableProxy.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Collections.Generic; namespace Org.BouncyCastle.Utilities.Collections { @@ -22,4 +23,28 @@ namespace Org.BouncyCastle.Utilities.Collections return inner.GetEnumerator(); } } + + internal sealed class EnumerableProxy<T> + : IEnumerable<T> + { + private readonly IEnumerable<T> m_inner; + + internal EnumerableProxy(IEnumerable<T> inner) + { + if (inner == null) + throw new ArgumentNullException("inner"); + + m_inner = inner; + } + + IEnumerator IEnumerable.GetEnumerator() + { + return m_inner.GetEnumerator(); + } + + IEnumerator<T> IEnumerable<T>.GetEnumerator() + { + return m_inner.GetEnumerator(); + } + } } |