本文整理汇总了C#中BsonClassMap.GetMemberMap方法的典型用法代码示例。如果您正苦于以下问题:C# BsonClassMap.GetMemberMap方法的具体用法?C# BsonClassMap.GetMemberMap怎么用?C# BsonClassMap.GetMemberMap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BsonClassMap
的用法示例。
在下文中一共展示了BsonClassMap.GetMemberMap方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
示例2: TestMapField
public void TestMapField() {
var classMap = new BsonClassMap<C>(cm => cm.MapField("f"));
var memberMap = classMap.GetMemberMap("f");
Assert.IsNotNull(memberMap);
Assert.AreEqual("f", memberMap.ElementName);
Assert.AreEqual("f", memberMap.MemberName);
}
示例3: TestIsReadOnlyPropertyOfAField
public void TestIsReadOnlyPropertyOfAField()
{
var classMap = new BsonClassMap<TestClass>(cm => cm.AutoMap());
var memberMap = classMap.GetMemberMap("Field");
Assert.IsFalse(memberMap.IsReadOnly);
}
示例4: TestSettingAProperty
public void TestSettingAProperty() {
var instance = new TestClass();
var classMap = new BsonClassMap<TestClass>(cm => cm.AutoMap());
var memberMap = classMap.GetMemberMap("Property");
memberMap.Setter(instance, 42);
Assert.AreEqual(42, instance.Property);
}
示例5: TestGettingAProperty
public void TestGettingAProperty() {
var instance = new TestClass { Property = 42 };
var classMap = new BsonClassMap<TestClass>(cm => cm.AutoMap());
var memberMap = classMap.GetMemberMap("Property");
int value = (int)memberMap.Getter(instance);
Assert.AreEqual(42, value);
}
示例6: TestOptsInMembers
public void TestOptsInMembers()
{
var convention = AttributeConventionPack.Instance;
var classMap = new BsonClassMap<TestClass>();
new ConventionRunner(convention).Apply(classMap);
Assert.AreEqual(1, classMap.DeclaredMemberMaps.Count());
Assert.AreEqual("fn", classMap.GetMemberMap("_firstName").ElementName);
}
示例7: TestConventionProfileStillUsesDefaults
public void TestConventionProfileStillUsesDefaults()
{
var classMap = new BsonClassMap<A>();
classMap.AutoMap();
var memberMap = classMap.GetMemberMap(x => x.S);
Assert.IsNotNull(memberMap);
}
示例8: TestGettingAField
public void TestGettingAField()
{
var instance = new TestClass { Field = 42 };
var classMap = new BsonClassMap<TestClass>(cm => cm.AutoMap());
var memberMap = classMap.GetMemberMap("Field");
int value = (int)memberMap.Getter(instance);
Assert.Equal(42, value);
}
示例9: TestMappingUsesMemberSerializationOptionsConventionDoesNotMatchWrongProperty
public void TestMappingUsesMemberSerializationOptionsConventionDoesNotMatchWrongProperty()
{
var pack = new ConventionPack();
pack.Add(new MemberSerializationOptionsConvention(typeof(ObjectId), new RepresentationSerializationOptions(BsonType.JavaScriptWithScope)));
ConventionRegistry.Register("test", pack, t => t == typeof(A));
var classMap = new BsonClassMap<A>(cm => cm.AutoMap());
var options = classMap.GetMemberMap("NoMatch").SerializationOptions;
Assert.IsNull(options);
}
示例10: TestMappingUsesMemberDefaultValueConventionDoesNotMatchWrongProperty
public void TestMappingUsesMemberDefaultValueConventionDoesNotMatchWrongProperty()
{
var pack = new ConventionPack();
pack.Add(new MemberDefaultValueConvention(typeof(int), 1));
ConventionRegistry.Register("test", pack, t => t == typeof(A));
var classMap = new BsonClassMap<A>(cm => cm.AutoMap());
var defaultValue = classMap.GetMemberMap("NoMatch").DefaultValue;
Assert.Equal(0L, defaultValue);
}
示例11: TestMappingUsesMemberDefaultValueConvention
public void TestMappingUsesMemberDefaultValueConvention()
{
var pack = new ConventionPack();
pack.Add(new MemberDefaultValueConvention(typeof(int), 1));
ConventionRegistry.Register("test", pack, t => t == typeof(A));
var classMap = new BsonClassMap<A>(cm => cm.AutoMap());
var defaultValue = classMap.GetMemberMap("Match").DefaultValue;
Assert.IsInstanceOf<int>(defaultValue);
Assert.AreEqual(1, defaultValue);
}
示例12: TestMappingUsesMemberSerializationOptionsConventionDoesNotOverrideAttribute
public void TestMappingUsesMemberSerializationOptionsConventionDoesNotOverrideAttribute()
{
var pack = new ConventionPack();
pack.Add(new MemberSerializationOptionsConvention(typeof(ObjectId), new RepresentationSerializationOptions(BsonType.JavaScriptWithScope)));
ConventionRegistry.Register("test", pack, t => t == typeof(B));
var classMap = new BsonClassMap<B>(cm => cm.AutoMap());
var options = classMap.GetMemberMap("Match").SerializationOptions;
Assert.IsInstanceOf<RepresentationSerializationOptions>(options);
Assert.AreEqual(BsonType.ObjectId, ((RepresentationSerializationOptions)options).Representation);
}
示例13: TestMappingUsesMemberDefaultValueConventionDoesNotOverrideAttribute
public void TestMappingUsesMemberDefaultValueConventionDoesNotOverrideAttribute()
{
var pack = new ConventionPack();
pack.Add(new MemberDefaultValueConvention(typeof(int), 1));
ConventionRegistry.Register("test", pack, t => t == typeof(B));
var classMap = new BsonClassMap<B>(cm => cm.AutoMap());
var defaultValue = classMap.GetMemberMap("Match").DefaultValue;
Assert.IsType<int>(defaultValue);
Assert.Equal(2, defaultValue);
}
示例14: TestConventionProfileStillUsesDefaults
public void TestConventionProfileStillUsesDefaults()
{
#pragma warning disable 618
var conventions = new ConventionProfile();
conventions.SetElementNameConvention(new CamelCaseElementNameConvention());
BsonClassMap.RegisterConventions(conventions, t => t == typeof(A));
#pragma warning restore 618
var classMap = new BsonClassMap<A>();
classMap.AutoMap();
var memberMap = classMap.GetMemberMap(x => x.S);
Assert.IsNotNull(memberMap);
}
示例15: TestSetElementNameThrowsWhenElementNameIsNull
public void TestSetElementNameThrowsWhenElementNameIsNull()
{
var classMap = new BsonClassMap<TestClass>(cm => cm.AutoMap());
var memberMap = classMap.GetMemberMap("Property");
Assert.Throws<ArgumentNullException>(() => { memberMap.SetElementName(null); });
}