本文整理汇总了C#中BsonClassMap.MapMember方法的典型用法代码示例。如果您正苦于以下问题:C# BsonClassMap.MapMember方法的具体用法?C# BsonClassMap.MapMember怎么用?C# BsonClassMap.MapMember使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BsonClassMap
的用法示例。
在下文中一共展示了BsonClassMap.MapMember方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestConvention
public void TestConvention(BsonType value)
{
var convention = new EnumRepresentationConvention(value);
var classMap = new BsonClassMap<TestClass>();
var nonEnumMemberMap = classMap.MapMember(x => x.NonEnum);
var defaultEnumMemberMap = classMap.MapMember(x => x.DefaultEnum);
var changedEnumMemberMap = classMap.MapMember(x => x.ChangedRepresentationEnum);
convention.Apply(nonEnumMemberMap);
convention.Apply(changedEnumMemberMap);
Assert.AreEqual(value, ((IRepresentationConfigurable)(changedEnumMemberMap.GetSerializer())).Representation);
}
示例2: TestCamelCaseElementNameConvention
public void TestCamelCaseElementNameConvention()
{
var convention = new CamelCaseElementNameConvention();
var classMap = new BsonClassMap<TestClass>();
convention.Apply(classMap.MapMember(x => x.FirstName));
convention.Apply(classMap.MapMember(x => x.Age));
convention.Apply(classMap.MapMember(x => x._DumbName));
convention.Apply(classMap.MapMember(x => x.lowerCase));
Assert.AreEqual("firstName", classMap.GetMemberMap(x => x.FirstName).ElementName);
Assert.AreEqual("age", classMap.GetMemberMap(x => x.Age).ElementName);
Assert.AreEqual("_DumbName", classMap.GetMemberMap(x => x._DumbName).ElementName);
Assert.AreEqual("lowerCase", classMap.GetMemberMap(x => x.lowerCase).ElementName);
}
示例3: TestConvention
public void TestConvention(BsonType value)
{
var convention = new EnumRepresentationConvention(value);
var classMap = new BsonClassMap<TestClass>();
var nonEnumMemberMap = classMap.MapMember(x => x.NonEnum);
var defaultEnumMemberMap = classMap.MapMember(x => x.DefaultEnum);
var changedEnumMemberMap = classMap.MapMember(x => x.ChangedRepresentationEnum);
convention.Apply(nonEnumMemberMap);
convention.Apply(changedEnumMemberMap);
Assert.IsNull(nonEnumMemberMap.SerializationOptions);
Assert.IsNull(defaultEnumMemberMap.SerializationOptions);
Assert.AreEqual(value, ((RepresentationSerializationOptions)changedEnumMemberMap.SerializationOptions).Representation);
}
示例4: TestShouldDowncaseOnlyFirstCharByDefault
public void TestShouldDowncaseOnlyFirstCharByDefault()
{
var convention = new CamelCaseElementNameConvention();
var classMap = new BsonClassMap<TestClass>();
var firstName = classMap.MapMember(x => x.FirstName);
var age = classMap.MapMember(x => x.Age);
var allCaps = classMap.MapMember(x => x.ALLCAPS);
convention.Apply(firstName);
convention.Apply(age);
convention.Apply(allCaps);
Assert.AreEqual("firstName", firstName.ElementName);
Assert.AreEqual("age", age.ElementName);
Assert.AreEqual("aLLCAPS", allCaps.ElementName);
}
示例5: TestConventionOverride
public void TestConventionOverride()
{
var int64Convention = new EnumRepresentationConvention(BsonType.Int64);
var strConvention = new EnumRepresentationConvention(BsonType.String);
var classMap = new BsonClassMap<TestClass>();
var memberMap = classMap.MapMember(x => x.ChangedRepresentationEnum);
int64Convention.Apply(memberMap);
strConvention.Apply(memberMap);
Assert.AreEqual(BsonType.String, ((IRepresentationConfigurable)(memberMap.GetSerializer())).Representation);
}
示例6: TestApply
public void TestApply(bool value)
{
var subject = new IgnoreIfDefaultConvention(value);
var classMap = new BsonClassMap<TestClass>();
var memberMap = classMap.MapMember(x => x.Id);
subject.Apply(memberMap);
Assert.AreEqual(value, memberMap.IgnoreIfDefault);
}
示例7: TestCamelCaseElementNameConvention
public void TestCamelCaseElementNameConvention()
{
var convention = new CamelCaseElementNameConvention();
var classMap = new BsonClassMap<TestClass>();
var firstName = classMap.MapMember(x => x.FirstName);
var age = classMap.MapMember(x => x.Age);
var _dumbName = classMap.MapMember(x => x._DumbName);
var lowerCase = classMap.MapMember(x => x.lowerCase);
convention.Apply(firstName);
convention.Apply(age);
convention.Apply(_dumbName);
convention.Apply(lowerCase);
Assert.AreEqual("firstName", firstName.ElementName);
Assert.AreEqual("age", age.ElementName);
Assert.AreEqual("_DumbName", _dumbName.ElementName);
Assert.AreEqual("lowerCase", lowerCase.ElementName);
}
示例8: TestShouldHandleNameStartingWithNonLetter
public void TestShouldHandleNameStartingWithNonLetter()
{
var convention = new CamelCaseElementNameConvention();
var classMap = new BsonClassMap<TestClass>();
var _dumbName = classMap.MapMember(x => x._dumbName);
convention.Apply(_dumbName);
Assert.AreEqual("_dumbName", _dumbName.ElementName);
}
示例9: TestShouldNotChangeIfAlreadyCamelCased
public void TestShouldNotChangeIfAlreadyCamelCased()
{
var convention = new CamelCaseElementNameConvention();
var classMap = new BsonClassMap<TestClass>();
var lowerCase = classMap.MapMember(x => x.camelCasedName);
convention.Apply(lowerCase);
Assert.AreEqual("camelCasedName", lowerCase.ElementName);
}
示例10: TestShouldDowncaseCertainNumberOfChars
public void TestShouldDowncaseCertainNumberOfChars(int charsToDowncase, string expected)
{
var convention = new CamelCaseElementNameConvention(charsToDowncase);
var classMap = new BsonClassMap<TestClass>();
var ioStream = classMap.MapMember(x => x.ALLCAPS);
convention.Apply(ioStream);
Assert.AreEqual(expected, ioStream.ElementName);
}
示例11: Test
public void Test()
{
var convention = new DelegateMemberMapConvention("test", m => m.SetElementName("blah"));
Assert.AreEqual("test", convention.Name);
var classMap = new BsonClassMap<TestClass>();
var member = classMap.MapMember(x => x.FirstName);
convention.Apply(member);
Assert.AreEqual("blah", member.ElementName);
}
示例12: MapField
// private methods
private void MapField(BsonClassMap classMap, FieldInfo fieldInfo)
{
if (fieldInfo.IsInitOnly || fieldInfo.IsLiteral)
{
// we can't write
return;
}
classMap.MapMember(fieldInfo);
}
示例13: MapProperty
private void MapProperty(BsonClassMap classMap, PropertyInfo propertyInfo)
{
if (!propertyInfo.CanRead || (!propertyInfo.CanWrite && classMap.ClassType.Namespace != null))
{
// we can't write or it is anonymous...
return;
}
// skip indexers
if (propertyInfo.GetIndexParameters().Length != 0)
{
return;
}
// skip overridden properties (they are already included by the base class)
var getMethodInfo = propertyInfo.GetGetMethod(true);
if (getMethodInfo.IsVirtual && getMethodInfo.GetBaseDefinition().DeclaringType != classMap.ClassType)
{
return;
}
classMap.MapMember(propertyInfo);
}
示例14: OptInMembersWithBsonMemberMapModifierAttribute
private void OptInMembersWithBsonMemberMapModifierAttribute(BsonClassMap classMap)
{
// let other fields opt-in if they have any IBsonMemberMapAttribute attributes
foreach (var fieldInfo in classMap.ClassType.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly))
{
var hasAttribute = fieldInfo.GetCustomAttributes(typeof(IBsonMemberMapAttribute), false).Any();
if (hasAttribute)
{
classMap.MapMember(fieldInfo);
}
}
// let other properties opt-in if they have any IBsonMemberMapAttribute attributes
foreach (var propertyInfo in classMap.ClassType.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly))
{
var hasAttribute = propertyInfo.GetCustomAttributes(typeof(IBsonMemberMapAttribute), false).Any();
if (hasAttribute)
{
classMap.MapMember(propertyInfo);
}
}
}
示例15: Apply
public void Apply(BsonClassMap classMap)
{
var members = _convention.FindMembers(classMap.ClassType);
foreach (var member in members)
{
classMap.MapMember(member);
}
}