lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From synhers...@apache.org
Subject [6/6] lucenenet git commit: Changing SPIClassIterator to only accept classes with default ctor or IDict<string, string> parameter
Date Thu, 01 Sep 2016 21:29:21 GMT
Changing SPIClassIterator to only accept classes with default ctor or IDict<string,string>
parameter


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

Branch: refs/heads/master
Commit: 859d37ddfa7696f5ca4f4f4e5c31204cac3ea61e
Parents: a4d0c41
Author: Connie Yau <conniey@microsoft.com>
Authored: Wed Aug 31 19:06:19 2016 -0700
Committer: Connie Yau <conniey@microsoft.com>
Committed: Thu Sep 1 10:29:47 2016 -0700

----------------------------------------------------------------------
 src/Lucene.Net.Core/Util/SPIClassIterator.cs | 26 +++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/859d37dd/src/Lucene.Net.Core/Util/SPIClassIterator.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Util/SPIClassIterator.cs b/src/Lucene.Net.Core/Util/SPIClassIterator.cs
index 8706c3d..1e11713 100644
--- a/src/Lucene.Net.Core/Util/SPIClassIterator.cs
+++ b/src/Lucene.Net.Core/Util/SPIClassIterator.cs
@@ -79,7 +79,30 @@ namespace Lucene.Net.Util
                     {
                         try
                         {
-                            if (IsInvokableSubclassOf<S>(type))
+                            if (!IsInvokableSubclassOf<S>(type))
+                            {
+                                continue;
+                            }
+
+                            // We are looking for types with a default ctor
+                            // (which is used in NamedSPILoader) or has a single parameter
+                            // of type IDictionary<string, string> (for AnalysisSPILoader)
+                            var matchingCtors = type.GetConstructors().Where(ctor =>
+                            {
+                                var parameters = ctor.GetParameters();
+
+                                switch (parameters.Length)
+                                {
+                                    case 0: // default ctor
+                                        return true;
+                                    case 1:
+                                        return typeof(IDictionary<string, string>).IsAssignableFrom(parameters[0].ParameterType);
+                                    default:
+                                        return false;
+                                }
+                            });
+
+                            if (matchingCtors.Any())
                             {
                                 types.Add(type);
                             }
@@ -102,7 +125,6 @@ namespace Lucene.Net.Util
             return typeof(S).IsAssignableFrom(type) && !type.IsAbstract &&
!type.IsInterface;
         }
 
-
         public static SPIClassIterator<S> Get()
         {
             return new SPIClassIterator<S>();


Mime
View raw message