lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From paulir...@apache.org
Subject git commit: Bugfix to SPIClassIterator to support unloaded referenced assemblies
Date Tue, 12 Nov 2013 22:59:15 GMT
Updated Branches:
  refs/heads/branch_4x eef5d7a0b -> 4865dce05


Bugfix to SPIClassIterator to support unloaded referenced assemblies

i.e. Facets assembly for codecs


Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/4865dce0
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/4865dce0
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/4865dce0

Branch: refs/heads/branch_4x
Commit: 4865dce05ff9fc4b9264f670955f97300ec0f1e5
Parents: eef5d7a
Author: Paul Irwin <paulirwin@gmail.com>
Authored: Tue Nov 12 17:58:23 2013 -0500
Committer: Paul Irwin <paulirwin@gmail.com>
Committed: Tue Nov 12 17:58:23 2013 -0500

----------------------------------------------------------------------
 src/core/Util/SPIClassIterator.cs | 38 ++++++++++++++++++++++++++++++----
 1 file changed, 34 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/4865dce0/src/core/Util/SPIClassIterator.cs
----------------------------------------------------------------------
diff --git a/src/core/Util/SPIClassIterator.cs b/src/core/Util/SPIClassIterator.cs
index 0d865fa..f58e870 100644
--- a/src/core/Util/SPIClassIterator.cs
+++ b/src/core/Util/SPIClassIterator.cs
@@ -12,17 +12,22 @@ namespace Lucene.Net.Util
     /// <typeparam name="S"></typeparam>
     public class SPIClassIterator<S> : IEnumerable<Type>
     {
-        private static List<Type> _types;
+        private static HashSet<Type> _types;
 
         static SPIClassIterator()
         {
-            _types = new List<Type>();
+            _types = new HashSet<Type>();
 
-            foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
+            // .NET Port Hack: We do a 2-level deep check here because if the assembly you're
+            // hoping would be loaded hasn't been loaded yet into the app domain,
+            // it is unavailable. So we go to the next level on each and check each referenced
+            // assembly.
+
+            foreach (var loadedAssembly in AppDomain.CurrentDomain.GetAssemblies())
             {
                 try
                 {
-                    foreach (var type in assembly.GetTypes())
+                    foreach (var type in loadedAssembly.GetTypes())
                     {
                         try
                         {
@@ -39,6 +44,31 @@ namespace Lucene.Net.Util
                 {
                     // swallow
                 }
+
+                foreach (var assemblyName in loadedAssembly.GetReferencedAssemblies())
+                {                    
+                    try
+                    {
+                        var assembly = Assembly.Load(assemblyName);
+
+                        foreach (var type in assembly.GetTypes())
+                        {
+                            try
+                            {
+                                if (typeof(S).IsAssignableFrom(type) && !type.IsAbstract
&& !type.IsInterface && type.GetConstructor(Type.EmptyTypes) != null)
+                                    _types.Add(type);
+                            }
+                            catch
+                            {
+                                // swallow
+                            }
+                        }
+                    }
+                    catch
+                    {
+                        // swallow
+                    }
+                }
             }
         }
 


Mime
View raw message