Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions MongoDB.Bson/MongoDB.Bson.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
<Compile Include="Serialization\Conventions\CamelCaseElementNameConvention.cs" />
<Compile Include="Serialization\Conventions\HierarchicalDiscriminatorConvention.cs" />
<Compile Include="Serialization\Conventions\LookupIdGeneratorConvention.cs" />
<Compile Include="Serialization\Conventions\LowerCaseElementNameConvention.cs" />
<Compile Include="Serialization\Conventions\MemberNameElementNameConvention.cs" />
<Compile Include="Serialization\Conventions\NamedExtraElementsMemberConvention.cs" />
<Compile Include="Serialization\Conventions\NamedIdMemberConvention.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Reflection;

namespace MongoDB.Bson.Serialization.Conventions
{
/// <summary>
/// Represents an element name convention where the element name is the member name being all lower cased.
/// </summary>
public class LowerCaseElementNameConvention : IElementNameConvention
{
/// <summary>
/// Gets the element name for a member.
/// </summary>
/// <param name="member">The member.</param>
/// <returns>The element name.</returns>
public string GetElementName(MemberInfo member)
{
return member.Name.ToLowerInvariant();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,15 @@ public void TestCamelCaseElementNameConvention()
Assert.AreEqual("_DumbName", convention.GetElementName(typeof(TestClass).GetProperty("_DumbName")));
Assert.AreEqual("lowerCase", convention.GetElementName(typeof(TestClass).GetProperty("lowerCase")));
}

[Test]
public void TestLowerCaseElementNameConvention()
{
var convention = new LowerCaseElementNameConvention();
Assert.AreEqual("firstname", convention.GetElementName(typeof(TestClass).GetProperty("FirstName")));
Assert.AreEqual("age", convention.GetElementName(typeof(TestClass).GetProperty("Age")));
Assert.AreEqual("_dumbname", convention.GetElementName(typeof(TestClass).GetProperty("_DumbName")));
Assert.AreEqual("lowercase", convention.GetElementName(typeof(TestClass).GetProperty("lowerCase")));
}
}
}