diff --git a/MongoDB.Bson/MongoDB.Bson.csproj b/MongoDB.Bson/MongoDB.Bson.csproj index a43b55412d3..ba6677c7d3a 100644 --- a/MongoDB.Bson/MongoDB.Bson.csproj +++ b/MongoDB.Bson/MongoDB.Bson.csproj @@ -108,6 +108,7 @@ + diff --git a/MongoDB.Bson/Serialization/Conventions/LowerCaseElementNameConvention.cs b/MongoDB.Bson/Serialization/Conventions/LowerCaseElementNameConvention.cs new file mode 100644 index 00000000000..991a402ecda --- /dev/null +++ b/MongoDB.Bson/Serialization/Conventions/LowerCaseElementNameConvention.cs @@ -0,0 +1,21 @@ +using System; +using System.Reflection; + +namespace MongoDB.Bson.Serialization.Conventions +{ + /// + /// Represents an element name convention where the element name is the member name being all lower cased. + /// + public class LowerCaseElementNameConvention : IElementNameConvention + { + /// + /// Gets the element name for a member. + /// + /// The member. + /// The element name. + public string GetElementName(MemberInfo member) + { + return member.Name.ToLowerInvariant(); + } + } +} \ No newline at end of file diff --git a/MongoDB.BsonUnitTests/DefaultSerializer/Conventions/ElementNameConventionsTests.cs b/MongoDB.BsonUnitTests/DefaultSerializer/Conventions/ElementNameConventionsTests.cs index 6f3f6a53570..237db99bf5e 100644 --- a/MongoDB.BsonUnitTests/DefaultSerializer/Conventions/ElementNameConventionsTests.cs +++ b/MongoDB.BsonUnitTests/DefaultSerializer/Conventions/ElementNameConventionsTests.cs @@ -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"))); + } } }