From fda828187407a2613bc8df431d679a5af97f0c98 Mon Sep 17 00:00:00 2001 From: Jeffrey Schultz Date: Sun, 5 Nov 2017 04:35:48 +0200 Subject: [PATCH] change to support compilation under .NET Core --- .../CompositionAopProxyTypeBuilder.cs | 2 +- .../DecoratorAopProxyTypeBuilder.cs | 2 +- .../InheritanceAopProxyTypeBuilder.cs | 2 +- src/Spring/Spring.Aop/Aop/IThrowsAdvice.cs | 2 +- src/Spring/Spring.Core/ContextClassDiagram.cd | 153 ------------------ src/Spring/Spring.Core/Expressions/OpLike.cs | 112 +++++++++++-- .../MethodInjectingInstantiationStrategy.cs | 2 +- .../Factory/Xml/spring-objects-2.0.xsx | 88 ---------- .../Proxy/CompositionProxyTypeBuilder.cs | 2 +- .../Proxy/InheritanceProxyTypeBuilder.cs | 2 +- .../Context/Support/testobject.xsx | 3 - .../Factory/Xml/ReadOnlyXmlTestResource.cs | 5 +- 12 files changed, 109 insertions(+), 266 deletions(-) delete mode 100644 src/Spring/Spring.Core/ContextClassDiagram.cd delete mode 100644 src/Spring/Spring.Core/Objects/Factory/Xml/spring-objects-2.0.xsx delete mode 100644 test/Spring/Spring.Core.Tests/Context/Support/testobject.xsx diff --git a/src/Spring/Spring.Aop/Aop/Framework/DynamicProxy/CompositionAopProxyTypeBuilder.cs b/src/Spring/Spring.Aop/Aop/Framework/DynamicProxy/CompositionAopProxyTypeBuilder.cs index 6565d037..1e52759a 100644 --- a/src/Spring/Spring.Aop/Aop/Framework/DynamicProxy/CompositionAopProxyTypeBuilder.cs +++ b/src/Spring/Spring.Aop/Aop/Framework/DynamicProxy/CompositionAopProxyTypeBuilder.cs @@ -114,7 +114,7 @@ namespace Spring.Aop.Framework.DynamicProxy } Type proxyType; - proxyType = typeBuilder.CreateType(); + proxyType = typeBuilder.CreateTypeInfo(); // set target method references foreach (DictionaryEntry entry in targetMethods) diff --git a/src/Spring/Spring.Aop/Aop/Framework/DynamicProxy/DecoratorAopProxyTypeBuilder.cs b/src/Spring/Spring.Aop/Aop/Framework/DynamicProxy/DecoratorAopProxyTypeBuilder.cs index e8892cfd..ca9314ac 100644 --- a/src/Spring/Spring.Aop/Aop/Framework/DynamicProxy/DecoratorAopProxyTypeBuilder.cs +++ b/src/Spring/Spring.Aop/Aop/Framework/DynamicProxy/DecoratorAopProxyTypeBuilder.cs @@ -149,7 +149,7 @@ namespace Spring.Aop.Framework.DynamicProxy ImplementIAopProxy(typeBuilder); Type proxyType; - proxyType = typeBuilder.CreateType(); + proxyType = typeBuilder.CreateTypeInfo(); // set target method references foreach (DictionaryEntry entry in targetMethods) diff --git a/src/Spring/Spring.Aop/Aop/Framework/DynamicProxy/InheritanceAopProxyTypeBuilder.cs b/src/Spring/Spring.Aop/Aop/Framework/DynamicProxy/InheritanceAopProxyTypeBuilder.cs index 7368b1ad..26256398 100644 --- a/src/Spring/Spring.Aop/Aop/Framework/DynamicProxy/InheritanceAopProxyTypeBuilder.cs +++ b/src/Spring/Spring.Aop/Aop/Framework/DynamicProxy/InheritanceAopProxyTypeBuilder.cs @@ -168,7 +168,7 @@ namespace Spring.Aop.Framework.DynamicProxy ImplementIAopProxy(typeBuilder); Type proxyType; - proxyType = typeBuilder.CreateType(); + proxyType = typeBuilder.CreateTypeInfo(); // set target method references foreach (DictionaryEntry entry in targetMethods) diff --git a/src/Spring/Spring.Aop/Aop/IThrowsAdvice.cs b/src/Spring/Spring.Aop/Aop/IThrowsAdvice.cs index 22d0e406..ab87d372 100644 --- a/src/Spring/Spring.Aop/Aop/IThrowsAdvice.cs +++ b/src/Spring/Spring.Aop/Aop/IThrowsAdvice.cs @@ -44,7 +44,7 @@ namespace Spring.Aop /// examples would include the ubiquitous logging of any such exceptions, /// monitoring the number and type of exceptions and sending emails to /// a support desk once certain criteria have been met, wrapping generic - /// exceptions such as in + /// exceptions such as System.Data.SqlClient.SqlException in /// exceptions that are more meaningful to your business logic, etc. ///

/// diff --git a/src/Spring/Spring.Core/ContextClassDiagram.cd b/src/Spring/Spring.Core/ContextClassDiagram.cd deleted file mode 100644 index 7a48ca13..00000000 --- a/src/Spring/Spring.Core/ContextClassDiagram.cd +++ /dev/null @@ -1,153 +0,0 @@ - - - - - - SHQRYAEIiGBAtMBASYTEWAQkWBAiChEMaAACCAFBXMg= - Context\Support\AbstractApplicationContext.cs - - - - - - - AAQACAAAAABAAACBAAQAAQAAABAAAAAAABAAAAACAEA= - Context\Support\AbstractXmlApplicationContext.cs - - - - - - AAQAAAAAAAAAAAAAAAQAAAAAABAAIAAAAAAAAAAEAAA= - Context\Support\GenericApplicationContext.cs - - - - - - AAAACAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAIAEAAA= - Context\Support\XmlApplicationContext.cs - - - - - - AAEAAAAAAAAAAAAIAAQAAAAAAgAAAAAAAAAAAAAAAAA= - Context\Support\StaticApplicationContext.cs - - - - - - AAAAAAAAAAAAggAAAQAAAAAABAAAAAAAAAAASAAAAAA= - Core\IO\ConfigurableResourceLoader.cs - - - - - - - AAQAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAACEA= - Context\IConfigurableApplicationContext.cs - - - - - - AAAAAAAAAAAAEAAAAACAAAQAAAAAAAAAAAAAAAAACAA= - Context\IApplicationContext.cs - - - - - - AAAAAAAAACAAAAAAAAAAQAAAAAAAAAAAIAAAAAAAAAA= - Context\ILifecycle.cs - - - - - - ABAAAAAAAAAAIIAACIAACAAAAAAAAgEMAAAAAAAAAIA= - Objects\Factory\IObjectFactory.cs - - - - - - AAAAAAAAAAAAAACAAAAAAAAIAAQAAAAgEAAAAAAAAAA= - Objects\Factory\Config\IAutowireCapableObjectFactory.cs - - - - - - AAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAQAA= - Objects\Factory\IHierarchicalObjectFactory.cs - - - - - - CAAAAAAAAAAAAAAAQABAEAAAAAAAAAAACAAAAAAAAAA= - Objects\Factory\IListableObjectFactory.cs - - - - - - AAAAAAAAAAAAAIAAAIAEAAAgAAAAAAAAAAAACABAAAA= - Objects\Factory\Config\IConfigurableListableObjectFactory.cs - - - - - - AAAAAAAABCAAAAAAAAACAAAAQAAEAAAAAAAAAQAAEAA= - Objects\Factory\Config\IConfigurableObjectFactory.cs - - - - - - AAAAAAAAEAAAABAIAAAAAAAAAAAAAAAAAAAAAgAAAIA= - Objects\Factory\Config\ISingletonObjectRegistry.cs - - - - - - ACAAAAAAAAAAAAAAAAAAAAAACAAAABAAAAAAAAAAAAA= - Context\IMessageSource.cs - - - - - - AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAA= - Context\IApplicationEventPublisher.cs - - - - - - AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAAAAA= - Core\IO\IResourceLoader.cs - - - - - - AAAAAAAAAAAAAAAAAAAAAAAAAAACAAAAQAAAAAAAAIA= - Objects\Events\IEventRegistry.cs - - - - - - CBAAAAAAAAAAAAAAQAAEEAAgABAAAAAAAAAAAAAAEAA= - Objects\Factory\Support\IObjectDefinitionRegistry.cs - - - - \ No newline at end of file diff --git a/src/Spring/Spring.Core/Expressions/OpLike.cs b/src/Spring/Spring.Core/Expressions/OpLike.cs index f1c94683..14c363b0 100644 --- a/src/Spring/Spring.Core/Expressions/OpLike.cs +++ b/src/Spring/Spring.Core/Expressions/OpLike.cs @@ -20,10 +20,8 @@ using System; using System.Runtime.Serialization; -#if !MONO_2_0 -using Microsoft.VisualBasic; -using Microsoft.VisualBasic.CompilerServices; -#endif +using System.Text; +using System.Text.RegularExpressions; namespace Spring.Expressions { @@ -37,7 +35,7 @@ namespace Spring.Expressions /// /// Create a new instance /// - public OpLike():base() + public OpLike() { } @@ -48,7 +46,7 @@ namespace Spring.Expressions : base(info, context) { } - + /// /// Returns a value for the logical LIKE operator node. /// @@ -59,14 +57,100 @@ namespace Spring.Expressions /// protected override object Get(object context, EvaluationContext evalContext) { -#if !MONO_2_0 - string text = GetLeftValue( context, evalContext ) as string; - string pattern = GetRightValue( context, evalContext ) as string; + string text = GetLeftValue(context, evalContext) as string; + string pattern = GetRightValue(context, evalContext) as string; - return LikeOperator.LikeString(text, pattern, CompareMethod.Text); -#else - throw new NotSupportedException("'like' operator is only supported in .NET 2.0 or higher."); -#endif + return LikeString(text, pattern); + } + + private static bool LikeString(string Source, string Pattern) + { + if (string.IsNullOrEmpty(Source) && string.IsNullOrEmpty(Pattern)) + { + return true; + // LAMESPEC : MSDN states "if either string or pattern is an empty string, the result is False." + // but "" Like "[]" returns True + } + + if ((string.IsNullOrEmpty(Source) || string.IsNullOrEmpty(Pattern)) && string.Compare(Pattern, "[]") != 0) + { + return false; + } + + RegexOptions options = RegexOptions.Singleline | RegexOptions.CultureInvariant | RegexOptions.IgnoreCase; + + string regexString = ConvertLikeExpression(Pattern); + Regex regexpr = new Regex(regexString, options); + + //Console.WriteLine("{0} --> {1}", Pattern, regexString) + + return regexpr.IsMatch(Source); + } + + private static string ConvertLikeExpression(string expression) + { + StringBuilder sb = new StringBuilder(); + + sb.Append("^"); + + for (int pos = 0; pos <= expression.Length - 1; pos++) + { + switch (expression[pos]) + { + case '?': + sb.Append('.'); + break; + case '*': + sb.Append('.').Append('*'); + break; + case '#': + sb.Append("\\d{1}"); + break; + case '[': + StringBuilder gsb = ConvertGroupSubexpression(expression, ref pos); + // skip groups of form [], i.e. empty strings + if (gsb.Length > 2) + { + sb.Append(gsb); + } + break; + default: + sb.Append(Regex.Escape(expression[pos].ToString())); + break; + } + } + + sb.Append("$"); + + return sb.ToString(); + } + + private static StringBuilder ConvertGroupSubexpression(string carr, ref int pos) + { + StringBuilder sb = new StringBuilder(); + bool negate = false; + + while (carr[pos] != ']') + { + if (negate) + { + sb.Append('^'); + negate = false; + } + if (carr[pos] == '!') + { + sb.Remove(1, sb.Length - 1); + negate = true; + } + else + { + sb.Append(carr[pos]); + } + pos = pos + 1; + } + sb.Append(']'); + + return sb; } } -} +} \ No newline at end of file diff --git a/src/Spring/Spring.Core/Objects/Factory/Support/MethodInjectingInstantiationStrategy.cs b/src/Spring/Spring.Core/Objects/Factory/Support/MethodInjectingInstantiationStrategy.cs index 4cbd630d..e13e53ca 100644 --- a/src/Spring/Spring.Core/Objects/Factory/Support/MethodInjectingInstantiationStrategy.cs +++ b/src/Spring/Spring.Core/Objects/Factory/Support/MethodInjectingInstantiationStrategy.cs @@ -293,7 +293,7 @@ namespace Spring.Objects.Factory.Support DefineConstructors(typeBuilder); DefineProperties(typeBuilder); DefineMethods(typeBuilder); - return typeBuilder.CreateType(); + return typeBuilder.CreateTypeInfo(); } private Type BaseType diff --git a/src/Spring/Spring.Core/Objects/Factory/Xml/spring-objects-2.0.xsx b/src/Spring/Spring.Core/Objects/Factory/Xml/spring-objects-2.0.xsx deleted file mode 100644 index d23d8609..00000000 --- a/src/Spring/Spring.Core/Objects/Factory/Xml/spring-objects-2.0.xsx +++ /dev/null @@ -1,88 +0,0 @@ - - - - - - - - - - - - - - <_x0028_group1_x0029__XmlChoice left="7243" top="43376" width="5292" height="3757" selected="0" zOrder="15" index="1" expanded="1"> - - - - - <_x0028_group1_x0029__XmlChoice left="19095" top="39111" width="5292" height="3757" selected="0" zOrder="25" index="1" expanded="0" /> - - - <_x0028_group1_x0029__XmlChoice left="19095" top="43376" width="5292" height="3757" selected="0" zOrder="29" index="1" expanded="0" /> - - - - - - - - - - - - - - - - - - - - - <_x0028_group1_x0029__XmlChoice left="7243" top="90291" width="5292" height="3757" selected="0" zOrder="53" index="1" expanded="0" /> - - - - <_x0028_group1_x0029__XmlChoice left="7243" top="98821" width="5292" height="3757" selected="0" zOrder="57" index="1" expanded="0" /> - - - <_x0028_group1_x0029__XmlChoice left="7243" top="103086" width="5292" height="3757" selected="0" zOrder="60" index="1" expanded="0" /> - - - - - - - - - - - - - <_x0028_scope_x0029__XmlSimpleType left="13169" top="128676" width="5292" height="3757" selected="0" zOrder="79" index="0" expanded="1" /> - - - <_x0028_lazy-init_x0029__XmlSimpleType left="13169" top="132941" width="5292" height="3757" selected="0" zOrder="83" index="0" expanded="1" /> - - - <_x0028_autowire_x0029__XmlSimpleType left="13169" top="137206" width="5292" height="3757" selected="0" zOrder="87" index="0" expanded="1" /> - - - <_x0028_dependency-check_x0029__XmlSimpleType left="13169" top="141471" width="5292" height="3757" selected="0" zOrder="91" index="0" expanded="1" /> - - - - <_x0028_group1_x0029__XmlChoice left="7243" top="150001" width="5292" height="3757" selected="0" zOrder="94" index="1" expanded="1"> - - - - - - <_x0028_default-dependency-check_x0029__XmlSimpleType left="13169" top="158531" width="5292" height="3757" selected="0" zOrder="104" index="0" expanded="1" /> - - - <_x0028_default-autowire_x0029__XmlSimpleType left="13169" top="162796" width="5292" height="3757" selected="0" zOrder="108" index="0" expanded="1" /> - - - \ No newline at end of file diff --git a/src/Spring/Spring.Core/Proxy/CompositionProxyTypeBuilder.cs b/src/Spring/Spring.Core/Proxy/CompositionProxyTypeBuilder.cs index 09537789..0fc1aef6 100644 --- a/src/Spring/Spring.Core/Proxy/CompositionProxyTypeBuilder.cs +++ b/src/Spring/Spring.Core/Proxy/CompositionProxyTypeBuilder.cs @@ -127,7 +127,7 @@ namespace Spring.Proxy ImplementCustom(typeBuilder); - return typeBuilder.CreateType(); + return typeBuilder.CreateTypeInfo(); } /// diff --git a/src/Spring/Spring.Core/Proxy/InheritanceProxyTypeBuilder.cs b/src/Spring/Spring.Core/Proxy/InheritanceProxyTypeBuilder.cs index fb6c2839..3a4b15b0 100644 --- a/src/Spring/Spring.Core/Proxy/InheritanceProxyTypeBuilder.cs +++ b/src/Spring/Spring.Core/Proxy/InheritanceProxyTypeBuilder.cs @@ -122,7 +122,7 @@ namespace Spring.Proxy new BaseProxyMethodBuilder(typeBuilder, this, false), BaseType, declaredMembersOnly); - return typeBuilder.CreateType(); + return typeBuilder.CreateTypeInfo(); } #endregion diff --git a/test/Spring/Spring.Core.Tests/Context/Support/testobject.xsx b/test/Spring/Spring.Core.Tests/Context/Support/testobject.xsx deleted file mode 100644 index ff71343b..00000000 --- a/test/Spring/Spring.Core.Tests/Context/Support/testobject.xsx +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/test/Spring/Spring.Core.Tests/Objects/Factory/Xml/ReadOnlyXmlTestResource.cs b/test/Spring/Spring.Core.Tests/Objects/Factory/Xml/ReadOnlyXmlTestResource.cs index 28b3be64..625bd23d 100644 --- a/test/Spring/Spring.Core.Tests/Objects/Factory/Xml/ReadOnlyXmlTestResource.cs +++ b/test/Spring/Spring.Core.Tests/Objects/Factory/Xml/ReadOnlyXmlTestResource.cs @@ -56,7 +56,10 @@ namespace Spring.Objects.Factory.Xml ConfigurableResourceLoader loader = new ConfigurableResourceLoader(); underlyingResource = loader.GetResource(fileName); } - underlyingResource = new FileSystemResource(fileName); + else + { + underlyingResource = new FileSystemResource(fileName); + } } ///