summary refs log tree commit diff
path: root/crypto/src/openpgp/PgpObjectFactory.cs
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2020-02-21 18:32:24 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2020-02-21 18:32:24 +0700
commitaa67c1309df1bfd1d9eac195fb82d9c75984901c (patch)
treece982075f278160c91badfb5e9159fd1e641faa3 /crypto/src/openpgp/PgpObjectFactory.cs
parentRefactoring (diff)
downloadBouncyCastle.NET-ed25519-aa67c1309df1bfd1d9eac195fb82d9c75984901c.tar.xz
Add utility method
Diffstat (limited to '')
-rw-r--r--crypto/src/openpgp/PgpObjectFactory.cs21
1 files changed, 20 insertions, 1 deletions
diff --git a/crypto/src/openpgp/PgpObjectFactory.cs b/crypto/src/openpgp/PgpObjectFactory.cs
index c5c6fcb68..c31cd221c 100644
--- a/crypto/src/openpgp/PgpObjectFactory.cs
+++ b/crypto/src/openpgp/PgpObjectFactory.cs
@@ -139,5 +139,24 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp
 			}
 			return result;
 		}
-	}
+
+        /// <summary>
+        /// Read all available objects, returning only those that are assignable to the specified type.
+        /// </summary>
+        /// <param name="type">The type of objects to return. All other objects are ignored.</param>
+        /// <returns>An <c>IList</c> containing the filtered objects from this factory, in order.</returns>
+        public IList FilterPgpObjects(Type type)
+        {
+            IList result = Platform.CreateArrayList();
+            PgpObject pgpObject;
+            while ((pgpObject = NextPgpObject()) != null)
+            {
+                if (type.IsAssignableFrom(pgpObject.GetType()))
+                {
+                    result.Add(pgpObject);
+                }
+            }
+            return result;
+        }
+    }
 }