You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by sy...@apache.org on 2016/09/01 21:29:21 UTC
[6/6] lucenenet git commit: Changing SPIClassIterator to only accept
classes with default ctor or IDict parameter
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 <co...@microsoft.com>
Authored: Wed Aug 31 19:06:19 2016 -0700
Committer: Connie Yau <co...@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>();