|
From: <jul...@us...> - 2011-02-16 16:33:10
|
Revision: 5381
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5381&view=rev
Author: julian-maughan
Date: 2011-02-16 16:33:03 +0000 (Wed, 16 Feb 2011)
Log Message:
-----------
Added support for 'field.camelcase-m-underscore' field naming strategy (NH-2357)
Modified Paths:
--------------
trunk/nhibernate/doc/reference/modules/basic_mapping.xml
trunk/nhibernate/src/NHibernate/NHibernate.csproj
trunk/nhibernate/src/NHibernate/Properties/PropertyAccessorFactory.cs
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
trunk/nhibernate/src/NHibernate.Test/PropertyTest/FieldClass.cs
trunk/nhibernate/src/NHibernate.Test/PropertyTest/FieldGetterFixture.cs
trunk/nhibernate/src/NHibernate.Test/PropertyTest/NoSetterAccessorFixture.cs
Added Paths:
-----------
trunk/nhibernate/src/NHibernate/Properties/CamelCaseMUnderscoreStrategy.cs
trunk/nhibernate/src/NHibernate.Test/PropertyTest/FieldCamelCaseMUnderscoreFixture.cs
trunk/nhibernate/src/NHibernate.Test/PropertyTest/NoSetterCamelCaseMUnderscoreFixture.cs
Modified: trunk/nhibernate/doc/reference/modules/basic_mapping.xml
===================================================================
--- trunk/nhibernate/doc/reference/modules/basic_mapping.xml 2011-02-11 16:07:38 UTC (rev 5380)
+++ trunk/nhibernate/doc/reference/modules/basic_mapping.xml 2011-02-16 16:33:03 UTC (rev 5381)
@@ -1295,7 +1295,7 @@
<entry>
<para>
The <literal>name</literal> attribute is converted to camel case to find the field.
- <literal><property name="Foo" ... ></literal> uses the field <literal>foo</literal>.
+ <literal><property name="FooBar" ... ></literal> uses the field <literal>fooBar</literal>.
</para>
</entry>
</row>
@@ -1305,18 +1305,28 @@
<para>
The <literal>name</literal> attribute is converted to camel case and prefixed with an
underscore to find the field.
- <literal><property name="Foo" ... ></literal> uses the field <literal>_foo</literal>.
+ <literal><property name="FooBar" ... ></literal> uses the field <literal>_fooBar</literal>.
</para>
- </entry>
+ </entry>
</row>
<row>
+ <entry><literal>camelcase-m-underscore</literal></entry>
+ <entry>
+ <para>
+ The <literal>name</literal> attribute is converted to camel case and prefixed with
+ the character <literal>m</literal> and an underscore to find the field.
+ <literal><property name="FooBar" ... ></literal> uses the field <literal>m_fooBar</literal>.
+ </para>
+ </entry>
+ </row>
+ <row>
<entry><literal>lowercase</literal></entry>
<entry>
<para>
The <literal>name</literal> attribute is converted to lower case to find the Field.
<literal><property name="FooBar" ... ></literal> uses the field <literal>foobar</literal>.
</para>
- </entry>
+ </entry>
</row>
<row>
<entry><literal>lowercase-underscore</literal></entry>
@@ -1333,7 +1343,7 @@
<entry>
<para>
The <literal>name</literal> attribute is prefixed with an underscore to find the field.
- <literal><property name="Foo" ... ></literal> uses the field <literal>_Foo</literal>.
+ <literal><property name="FooBar" ... ></literal> uses the field <literal>_FooBar</literal>.
</para>
</entry>
</row>
@@ -1343,7 +1353,7 @@
<para>
The <literal>name</literal> attribute is prefixed with the character
<literal>m</literal> to find the field.
- <literal><property name="Foo" ... ></literal> uses the field <literal>mFoo</literal>.
+ <literal><property name="FooBar" ... ></literal> uses the field <literal>mFooBar</literal>.
</para>
</entry>
</row>
@@ -1353,7 +1363,7 @@
<para>
The <literal>name</literal> attribute is prefixed with the character
<literal>m</literal> and an underscore to find the field.
- <literal><property name="Foo" ... ></literal> uses the field <literal>m_Foo</literal>.
+ <literal><property name="FooBar" ... ></literal> uses the field <literal>m_FooBar</literal>.
</para>
</entry>
</row>
Modified: trunk/nhibernate/src/NHibernate/NHibernate.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate/NHibernate.csproj 2011-02-11 16:07:38 UTC (rev 5380)
+++ trunk/nhibernate/src/NHibernate/NHibernate.csproj 2011-02-16 16:33:03 UTC (rev 5381)
@@ -307,6 +307,7 @@
<Compile Include="ObjectNotFoundException.cs" />
<Compile Include="PersistentObjectException.cs" />
<Compile Include="Persister\PersisterFactory.cs" />
+ <Compile Include="Properties\CamelCaseMUnderscoreStrategy.cs" />
<Compile Include="PropertyAccessException.cs" />
<Compile Include="PropertyNotFoundException.cs" />
<Compile Include="PropertyValueException.cs" />
Added: trunk/nhibernate/src/NHibernate/Properties/CamelCaseMUnderscoreStrategy.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Properties/CamelCaseMUnderscoreStrategy.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate/Properties/CamelCaseMUnderscoreStrategy.cs 2011-02-16 16:33:03 UTC (rev 5381)
@@ -0,0 +1,25 @@
+namespace NHibernate.Properties
+{
+ /// <summary>
+ /// Implementation of <see cref="IFieldNamingStrategy"/> for fields that are prefixed with
+ /// an <c>m_</c> and the PropertyName is changed to camelCase.
+ /// </summary>
+ public class CamelCaseMUnderscoreStrategy : IFieldNamingStrategy
+ {
+ #region IFieldNamingStrategy Members
+
+ /// <summary>
+ /// Converts the Property's name into a Field name by making the first character
+ /// of the <c>propertyName</c> lowercase and prefixing it with the letter 'm'
+ /// and an underscore.
+ /// </summary>
+ /// <param name="propertyName">The name of the mapped property.</param>
+ /// <returns>The name of the Field in CamelCase format prefixed with an 'm' and an underscore.</returns>
+ public string GetFieldName(string propertyName)
+ {
+ return "m_" + propertyName.Substring(0, 1).ToLowerInvariant() + propertyName.Substring(1);
+ }
+
+ #endregion
+ }
+}
Modified: trunk/nhibernate/src/NHibernate/Properties/PropertyAccessorFactory.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Properties/PropertyAccessorFactory.cs 2011-02-11 16:07:38 UTC (rev 5380)
+++ trunk/nhibernate/src/NHibernate/Properties/PropertyAccessorFactory.cs 2011-02-16 16:33:03 UTC (rev 5381)
@@ -26,6 +26,7 @@
accessors["readonly"] = new ReadOnlyAccessor();
accessors["field.camelcase"] = new FieldAccessor(new CamelCaseStrategy());
accessors["field.camelcase-underscore"] = new FieldAccessor(new CamelCaseUnderscoreStrategy());
+ accessors["field.camelcase-m-underscore"] = new FieldAccessor(new CamelCaseMUnderscoreStrategy());
accessors["field.lowercase"] = new FieldAccessor(new LowerCaseStrategy());
accessors["field.lowercase-underscore"] = new FieldAccessor(new LowerCaseUnderscoreStrategy());
accessors["field.pascalcase-underscore"] = new FieldAccessor(new PascalCaseUnderscoreStrategy());
@@ -33,6 +34,7 @@
accessors["field.pascalcase-m"] = new FieldAccessor(new PascalCaseMStrategy());
accessors["nosetter.camelcase"] = new NoSetterAccessor(new CamelCaseStrategy());
accessors["nosetter.camelcase-underscore"] = new NoSetterAccessor(new CamelCaseUnderscoreStrategy());
+ accessors["nosetter.camelcase-m-underscore"] = new NoSetterAccessor(new CamelCaseMUnderscoreStrategy());
accessors["nosetter.lowercase"] = new NoSetterAccessor(new LowerCaseStrategy());
accessors["nosetter.lowercase-underscore"] = new NoSetterAccessor(new LowerCaseUnderscoreStrategy());
accessors["nosetter.pascalcase-underscore"] = new NoSetterAccessor(new PascalCaseUnderscoreStrategy());
@@ -116,7 +118,7 @@
/// <term>camelcase</term>
/// <description>
/// The <c>name</c> attribute should be changed to CamelCase to find the field.
- /// <c><property name="Foo" ... ></c> finds a field <c>foo</c>.
+ /// <c><property name="FooBar" ... ></c> finds a field <c>fooBar</c>.
/// </description>
/// </item>
/// <item>
@@ -124,15 +126,23 @@
/// <description>
/// The <c>name</c> attribute should be changed to CamelCase and prefixed with
/// an underscore to find the field.
- /// <c><property name="Foo" ... ></c> finds a field <c>_foo</c>.
+ /// <c><property name="FooBar" ... ></c> finds a field <c>_fooBar</c>.
/// </description>
/// </item>
/// <item>
+ /// <term>camelcase-m-underscore</term>
+ /// <description>
+ /// The <c>name</c> attribute should be changed to CamelCase and prefixed with
+ /// an 'm' and underscore to find the field.
+ /// <c><property name="FooBar" ... ></c> finds a field <c>m_fooBar</c>.
+ /// </description>
+ /// </item>
+ /// <item>
/// <term>pascalcase-underscore</term>
/// <description>
/// The <c>name</c> attribute should be prefixed with an underscore
/// to find the field.
- /// <c><property name="Foo" ... ></c> finds a field <c>_Foo</c>.
+ /// <c><property name="FooBar" ... ></c> finds a field <c>_FooBar</c>.
/// </description>
/// </item>
/// <item>
@@ -140,14 +150,14 @@
/// <description>
/// The <c>name</c> attribute should be prefixed with an 'm' and underscore
/// to find the field.
- /// <c><property name="Foo" ... ></c> finds a field <c>m_Foo</c>.
+ /// <c><property name="FooBar" ... ></c> finds a field <c>m_FooBar</c>.
/// </description>
/// </item>
/// <item>
/// <term>pascalcase-m</term>
/// <description>
/// The <c>name</c> attribute should be prefixed with an 'm'.
- /// <c><property name="Foo" ... ></c> finds a field <c>mFoo</c>.
+ /// <c><property name="FooBar" ... ></c> finds a field <c>mFooBar</c>.
/// </description>
/// </item>
/// <item>
Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-02-11 16:07:38 UTC (rev 5380)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-02-16 16:33:03 UTC (rev 5381)
@@ -618,6 +618,8 @@
<Compile Include="NHSpecificTest\Properties\Model.cs" />
<Compile Include="PolymorphicGetAndLoad\Domain.cs" />
<Compile Include="PolymorphicGetAndLoad\PolymorphicGetAndLoadTest.cs" />
+ <Compile Include="PropertyTest\FieldCamelCaseMUnderscoreFixture.cs" />
+ <Compile Include="PropertyTest\NoSetterCamelCaseMUnderscoreFixture.cs" />
<Compile Include="TypesTest\CharClass.cs" />
<Compile Include="TypesTest\CharClassFixture.cs" />
<Compile Include="TypesTest\DateTimeClass.cs" />
Added: trunk/nhibernate/src/NHibernate.Test/PropertyTest/FieldCamelCaseMUnderscoreFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/PropertyTest/FieldCamelCaseMUnderscoreFixture.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/PropertyTest/FieldCamelCaseMUnderscoreFixture.cs 2011-02-16 16:33:03 UTC (rev 5381)
@@ -0,0 +1,20 @@
+using System;
+using NHibernate.Properties;
+using NUnit.Framework;
+
+namespace NHibernate.Test.PropertyTest
+{
+ [TestFixture]
+ public class FieldCamelCaseMUnderscoreFixture : FieldAccessorFixture
+ {
+ [SetUp]
+ public override void SetUp()
+ {
+ _accessor = PropertyAccessorFactory.GetPropertyAccessor("field.camelcase-m-underscore");
+ _getter = _accessor.GetGetter(typeof(FieldClass), "CamelMUnderscore");
+ _setter = _accessor.GetSetter(typeof(FieldClass), "CamelMUnderscore");
+ _instance = new FieldClass();
+ _instance.InitCamelCaseMUnderscore(0);
+ }
+ }
+}
Modified: trunk/nhibernate/src/NHibernate.Test/PropertyTest/FieldClass.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/PropertyTest/FieldClass.cs 2011-02-11 16:07:38 UTC (rev 5380)
+++ trunk/nhibernate/src/NHibernate.Test/PropertyTest/FieldClass.cs 2011-02-16 16:33:03 UTC (rev 5381)
@@ -14,6 +14,7 @@
private int _lowerunderscorefoo = 5;
private int lowerfoo = 6;
private int _PascalUnderscoreFoo = 7;
+ private int m_camelMUnderscore = 8;
public bool CamelUnderscoreFooGetterCalled = false;
public bool BlahGetterCalled = false;
@@ -21,6 +22,7 @@
public bool LowerUnderscoreFooGetterCalled = false;
public bool LowerFooGetterCalled = false;
public bool PascalUnderscoreFooCalled = false;
+ public bool CamelMUnderscoreGetterCalled = false;
public FieldClass()
{
@@ -60,7 +62,12 @@
{
_lowerunderscorefoo = value;
}
-
+
+ public void InitCamelCaseMUnderscore(int value)
+ {
+ m_camelMUnderscore = value;
+ }
+
public void Increment()
{
Id++;
@@ -70,6 +77,7 @@
_lowerunderscorefoo++;
_PascalUnderscoreFoo++;
lowerfoo++;
+ m_camelMUnderscore++;
}
public int CamelUnderscoreFoo
@@ -126,5 +134,14 @@
return _PascalUnderscoreFoo;
}
}
+
+ public int CamelMUnderscore
+ {
+ get
+ {
+ CamelMUnderscoreGetterCalled = true;
+ return m_camelMUnderscore;
+ }
+ }
}
}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate.Test/PropertyTest/FieldGetterFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/PropertyTest/FieldGetterFixture.cs 2011-02-11 16:07:38 UTC (rev 5380)
+++ trunk/nhibernate/src/NHibernate.Test/PropertyTest/FieldGetterFixture.cs 2011-02-16 16:33:03 UTC (rev 5381)
@@ -65,7 +65,7 @@
Assert.IsNull(fieldGetter.PropertyName, "no Property Names for fields.");
Assert.AreEqual(Int64.MaxValue, fieldGetter.Get(obj), "Get() for Int64");
}
-
+
[Test]
public void PascalCaseMUnderscoreNamingStrategy()
{
@@ -79,7 +79,21 @@
Assert.IsNull(fieldGetter.PropertyName, "no Property Names for fields.");
Assert.AreEqual(new TimeSpan(DateTime.Parse("2001-01-01").Ticks), fieldGetter.Get(obj), "Get() for TimeSpan");
}
+
+ [Test]
+ public void CamelCaseMUnderscoreNamingStrategy()
+ {
+ IGetter fieldGetter =
+ ReflectHelper.GetGetter(typeof(FieldGetterClass), "PropertyFive", "field.camelcase-m-underscore");
+ Assert.IsNotNull(fieldGetter, "should have found getter");
+ Assert.AreEqual(typeof(FieldAccessor.FieldGetter), fieldGetter.GetType(), "IGetter should be for a field.");
+ Assert.AreEqual(typeof(decimal), fieldGetter.ReturnType, "returns Decimal.");
+ Assert.IsNull(fieldGetter.Method, "no MethodInfo for fields.");
+ Assert.IsNull(fieldGetter.PropertyName, "no Property Names for fields.");
+ Assert.AreEqual(2.5m, fieldGetter.Get(obj), "Get() for Decimal");
+ }
+
public class FieldGetterClass
{
#pragma warning disable 414
@@ -88,6 +102,7 @@
private bool _propertyTwo = true;
private TimeSpan m_PropertyThree = new TimeSpan(DateTime.Parse("2001-01-01").Ticks);
private long _propertyfour = Int64.MaxValue;
+ private decimal m_propertyFive = 2.5m;
#pragma warning restore 414
}
Modified: trunk/nhibernate/src/NHibernate.Test/PropertyTest/NoSetterAccessorFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/PropertyTest/NoSetterAccessorFixture.cs 2011-02-11 16:07:38 UTC (rev 5380)
+++ trunk/nhibernate/src/NHibernate.Test/PropertyTest/NoSetterAccessorFixture.cs 2011-02-16 16:33:03 UTC (rev 5381)
@@ -20,6 +20,7 @@
protected bool _expectedLowerUnderscoreFooGetterCalled = false;
protected bool _expectedLowerFooGetterCalled = false;
protected bool _expectedPascalUnderscoreFooGetterCalled = false;
+ protected bool _expectedCamelMUnderscoreGetterCalled = false;
/// <summary>
/// SetUp the local fields for the test cases.
@@ -41,13 +42,11 @@
Assert.AreEqual(_expectedBlahGetterCalled, _instance.BlahGetterCalled, "pascalcase-m-underscore");
Assert.AreEqual(_expectedCamelBazGetterCalled, _instance.CamelBazGetterCalled, "camelcase");
- Assert.AreEqual(_expectedCamelUnderscoreFooGetterCalled, _instance.CamelUnderscoreFooGetterCalled,
- "camelcase-underscore");
- Assert.AreEqual(_expectedLowerUnderscoreFooGetterCalled, _instance.LowerUnderscoreFooGetterCalled,
- "lowercase-underscore");
+ Assert.AreEqual(_expectedCamelUnderscoreFooGetterCalled, _instance.CamelUnderscoreFooGetterCalled, "camelcase-underscore");
+ Assert.AreEqual(_expectedLowerUnderscoreFooGetterCalled, _instance.LowerUnderscoreFooGetterCalled, "lowercase-underscore");
Assert.AreEqual(_expectedLowerFooGetterCalled, _instance.LowerFooGetterCalled, "lowercase");
- Assert.AreEqual(_expectedPascalUnderscoreFooGetterCalled, _instance.PascalUnderscoreFooCalled,
- "pascalcase-underscore");
+ Assert.AreEqual(_expectedPascalUnderscoreFooGetterCalled, _instance.PascalUnderscoreFooCalled, "pascalcase-underscore");
+ Assert.AreEqual(_expectedCamelMUnderscoreGetterCalled, _instance.CamelMUnderscoreGetterCalled, "camelcase-m-underscore");
}
[Test]
Added: trunk/nhibernate/src/NHibernate.Test/PropertyTest/NoSetterCamelCaseMUnderscoreFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/PropertyTest/NoSetterCamelCaseMUnderscoreFixture.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/PropertyTest/NoSetterCamelCaseMUnderscoreFixture.cs 2011-02-16 16:33:03 UTC (rev 5381)
@@ -0,0 +1,22 @@
+using System;
+using NHibernate.Properties;
+using NUnit.Framework;
+
+namespace NHibernate.Test.PropertyTest
+{
+ [TestFixture]
+ public class NoSetterCamelCaseMUnderscoreFixture : NoSetterAccessorFixture
+ {
+ [SetUp]
+ public override void SetUp()
+ {
+ _expectedCamelMUnderscoreGetterCalled = true;
+
+ _accessor = PropertyAccessorFactory.GetPropertyAccessor("nosetter.camelcase-m-underscore");
+ _getter = _accessor.GetGetter(typeof(FieldClass), "CamelMUnderscore");
+ _setter = _accessor.GetSetter(typeof(FieldClass), "CamelMUnderscore");
+ _instance = new FieldClass();
+ _instance.InitCamelCaseMUnderscore(0);
+ }
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|