You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ibatis.apache.org by gb...@apache.org on 2007/03/07 19:37:41 UTC

svn commit: r515690 - in /ibatis/trunk/cs/mapper: IBatisNet.Common.Test/NUnit/CommonTests/Utilities/TypeResolverTest.cs IBatisNet.Common/Utilities/TypesResolver/TypeResolver.cs

Author: gbayon
Date: Wed Mar  7 10:37:40 2007
New Revision: 515690

URL: http://svn.apache.org/viewvc?view=rev&rev=515690
Log:
Fixed IBATISNET-215 Improve TypeResolver by ignoring space in type definition

Modified:
    ibatis/trunk/cs/mapper/IBatisNet.Common.Test/NUnit/CommonTests/Utilities/TypeResolverTest.cs
    ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/TypesResolver/TypeResolver.cs

Modified: ibatis/trunk/cs/mapper/IBatisNet.Common.Test/NUnit/CommonTests/Utilities/TypeResolverTest.cs
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.Common.Test/NUnit/CommonTests/Utilities/TypeResolverTest.cs?view=diff&rev=515690&r1=515689&r2=515690
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.Common.Test/NUnit/CommonTests/Utilities/TypeResolverTest.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.Common.Test/NUnit/CommonTests/Utilities/TypeResolverTest.cs Wed Mar  7 10:37:40 2007
@@ -13,6 +13,20 @@
     [TestFixture] 
     public class TypeResolverTest
     {
+
+        /// <summary>
+        /// Test space on generic type
+        /// </summary>
+        [Test]
+        public void TestTrimSpace()
+        {
+            Type genericType = TypeUtils.ResolveType("System.Collections.Generic.Dictionary`2[[System.String],[System.Int32]]");
+
+            Assert.IsNotNull(genericType);
+        }
+
+
+
         /// <summary>
         /// Test nullable resolver
         /// </summary>
@@ -59,6 +73,10 @@
         public void TestGenericDictionaryType()
         {
             IDictionary<string, int> dico = new Dictionary<string, int>();
+
+            Console.WriteLine(typeof(IDictionary<,>).FullName);
+            Console.WriteLine(dico.GetType().FullName);
+
             string assemblyQualifiedName = dico.GetType().AssemblyQualifiedName;
             Type listType = TypeUtils.ResolveType(assemblyQualifiedName);
 

Modified: ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/TypesResolver/TypeResolver.cs
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/TypesResolver/TypeResolver.cs?view=diff&rev=515690&r1=515689&r2=515690
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/TypesResolver/TypeResolver.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/TypesResolver/TypeResolver.cs Wed Mar  7 10:37:40 2007
@@ -85,14 +85,14 @@
         public virtual Type Resolve(string typeName)
         {
 #if dotnet2
-            Type type = ResolveGenericType(typeName);
+            Type type = ResolveGenericType(typeName.Replace(" ", string.Empty));
             if (type == null)
             {
-                type = ResolveType(typeName);
+                type = ResolveType(typeName.Replace(" ", string.Empty));
             }
             return type;
 #else
-            return ResolveType(typeName);
+            return ResolveType(typeName.Replace(" ", string.Empty));
 #endif
         }
         #endregion
@@ -300,7 +300,7 @@
         /// </remarks>
         internal class GenericArgumentsInfo
         {
-        #region Constants
+            #region Constants
 
             /// <summary>
             /// The generic arguments prefix.
@@ -310,27 +310,23 @@
             /// <summary>
             /// The generic arguments suffix.
             /// </summary>
-            public const string GENERIC_ARGUMENTS_SUFFIX = "],";
+            public const string GENERIC_ARGUMENTS_SUFFIX = "]]";
 
             /// <summary>
             /// The character that separates a list of generic arguments.
             /// </summary>
             public const string GENERIC_ARGUMENTS_SEPARATOR = "],[";
             
-            private const char GENERIC_ARGUMENT_SUFFIX = '[';
-            private const char GENERIC_ARGUMENT_PREFIX = ']';
+            #endregion
 
-        #endregion
+            #region Fields
 
-        #region Fields
+                private string _unresolvedGenericTypeName = string.Empty;
+                private string[] _unresolvedGenericArguments = null;
 
-            private string _unresolvedGenericTypeName = string.Empty;
-            private string _unresolvedGenericMethodName = string.Empty;
-            private string[] _unresolvedGenericArguments = null;
+                #endregion
 
-            #endregion
-
-        #region Constructor (s) / Destructor
+            #region Constructor (s) / Destructor
 
             /// <summary>
             /// Creates a new instance of the GenericArgumentsInfo class.
@@ -346,7 +342,7 @@
 
             #endregion
 
-        #region Properties
+            #region Properties
 
             /// <summary>
             /// The (unresolved) generic type name portion 
@@ -357,14 +353,6 @@
                 get { return _unresolvedGenericTypeName; }
             }
 
-            /// <summary>
-            /// The (unresolved) generic method name portion 
-            /// of the original value when parsing a generic method.
-            /// </summary>
-            public string GenericMethodName
-            {
-                get { return _unresolvedGenericMethodName; }
-            }
 
             /// <summary>
             /// Is the string value contains generic arguments ?
@@ -404,7 +392,7 @@
 
             #endregion
 
-        #region Methods
+            #region Methods
 
             /// <summary>
             /// Returns an array of unresolved generic arguments types.
@@ -439,27 +427,17 @@
                 if (!isMatch)
                 {
                     _unresolvedGenericTypeName = originalString;
-                    _unresolvedGenericMethodName = originalString;
                 }
                 else
                 {
-                    //.*'\d*\[\[
-                    //http://developpeur.journaldunet.com/tutoriel/php/030303php_regexp1a.shtml
-                    //http://www.asp-php.net/tutorial/asp-php/regexp.php
-
                     int argsStartIndex = originalString.IndexOf(GENERIC_ARGUMENTS_PREFIX);
                     int argsEndIndex = originalString.LastIndexOf(GENERIC_ARGUMENTS_SUFFIX);
                     if (argsEndIndex != -1)
                     {
-                        _unresolvedGenericMethodName = originalString.Remove(
-                            argsStartIndex, argsEndIndex - argsStartIndex + 1);
-
                         SplitGenericArguments(originalString.Substring(
-                            argsStartIndex + 1, argsEndIndex - argsStartIndex - 1));
+                            argsStartIndex + 1, argsEndIndex - argsStartIndex));
 
-                        _unresolvedGenericTypeName = originalString.Replace(
-                            originalString.Substring(argsStartIndex-2, argsEndIndex - argsStartIndex + 3),
-                            "`" + _unresolvedGenericArguments.Length);
+                        _unresolvedGenericTypeName = originalString.Remove(argsStartIndex, argsEndIndex - argsStartIndex + 2);
                     }
                 }
             }