|
From: <fab...@us...> - 2009-06-10 14:26:10
|
Revision: 4443
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4443&view=rev
Author: fabiomaulo
Date: 2009-06-10 14:25:57 +0000 (Wed, 10 Jun 2009)
Log Message:
-----------
Fix NH-1822
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Util/TypeNameParser.cs
trunk/nhibernate/src/NHibernate.Test/UtilityTest/TypeNameParserFixture.cs
Modified: trunk/nhibernate/src/NHibernate/Util/TypeNameParser.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Util/TypeNameParser.cs 2009-06-10 05:30:11 UTC (rev 4442)
+++ trunk/nhibernate/src/NHibernate/Util/TypeNameParser.cs 2009-06-10 14:25:57 UTC (rev 4443)
@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
+using System.Text.RegularExpressions;
namespace NHibernate.Util
{
@@ -14,6 +15,8 @@
{
private readonly string defaultNamespace;
private readonly string defaultAssembly;
+ private static readonly Regex WhiteSpaces = new Regex(@"[\t\r\n]", RegexOptions.Compiled);
+ private static readonly Regex MultipleSpaces = new Regex(@"[ ]+", RegexOptions.Compiled);
public TypeNameParser(string defaultNamespace, string defaultAssembly)
{
@@ -31,17 +34,18 @@
return new TypeNameParser(defaultNamespace, defaultAssembly).ParseTypeName(type);
}
- public AssemblyQualifiedTypeName ParseTypeName(string type)
+ public AssemblyQualifiedTypeName ParseTypeName(string typeName)
{
- if (type == null)
+ if (typeName == null)
{
- throw new ArgumentNullException("type");
+ throw new ArgumentNullException("typeName");
}
- if (type.Trim('[',']','\\', ',') == string.Empty)
+ var type = WhiteSpaces.Replace(typeName, " ");
+ type = MultipleSpaces.Replace(type, " ").Replace(", [", ",[").Replace("[ [", "[[").Replace("] ]", "]]");
+ if (type.Trim(' ','[', ']', '\\', ',') == string.Empty)
{
- throw new ArgumentException(string.Format("The type to parse is not a type name:{0}", type), "type");
+ throw new ArgumentException(string.Format("The type to parse is not a type name:{0}", typeName), "typeName");
}
-
int genericTypeArgsStartIdx = type.IndexOf('[');
int genericTypeArgsEndIdx = type.LastIndexOf(']');
int genericTypeCardinalityIdx = -1;
Modified: trunk/nhibernate/src/NHibernate.Test/UtilityTest/TypeNameParserFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/UtilityTest/TypeNameParserFixture.cs 2009-06-10 05:30:11 UTC (rev 4442)
+++ trunk/nhibernate/src/NHibernate.Test/UtilityTest/TypeNameParserFixture.cs 2009-06-10 14:25:57 UTC (rev 4443)
@@ -251,5 +251,19 @@
var a = TypeNameParser.Parse(typeName);
Assert.AreEqual(typeName, a.ToString());
}
+
+ [Test]
+ [Description("Parse with new lines")]
+ public void NH1822()
+ {
+ var typeName =
+ @"OldMutual.SalesGear.Data.ReferenceType`2[
+ [OldMutual.SalesGear.Reference.Core.Channel, OldMutual.SalesGear.Reference.Core],
+ [OldMutual.SalesGear.Reference.Core.Channels, OldMutual.SalesGear.Reference.Core]
+ ], OldMutual.SalesGear.Data";
+ var expected = "OldMutual.SalesGear.Data.ReferenceType`2[[OldMutual.SalesGear.Reference.Core.Channel, OldMutual.SalesGear.Reference.Core],[OldMutual.SalesGear.Reference.Core.Channels, OldMutual.SalesGear.Reference.Core]], OldMutual.SalesGear.Data";
+ var a = TypeNameParser.Parse(typeName);
+ Assert.That(a.ToString(), Is.EqualTo(expected));
+ }
}
}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|