本文整理汇总了C#中BsonClassMap类的典型用法代码示例。如果您正苦于以下问题:C# BsonClassMap类的具体用法?C# BsonClassMap怎么用?C# BsonClassMap使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BsonClassMap类属于命名空间,在下文中一共展示了BsonClassMap类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestDoesNotSetWhenNoIdExists
public void TestDoesNotSetWhenNoIdExists()
{
var classMap = new BsonClassMap<TestClass>(cm =>
{ });
_subject.PostProcess(classMap);
}
示例2: TestMapIdField
public void TestMapIdField() {
var classMap = new BsonClassMap<C>(cm => cm.MapIdField("f"));
var idMemberMap = classMap.IdMemberMap;
Assert.IsNotNull(idMemberMap);
Assert.AreEqual("_id", idMemberMap.ElementName);
Assert.AreEqual("f", idMemberMap.MemberName);
}
示例3: TestDoesNotSetWhenNoIdExists
public void TestDoesNotSetWhenNoIdExists()
{
var classMap = new BsonClassMap<TestClass>(cm =>
{ });
Assert.DoesNotThrow(() => _subject.PostProcess(classMap));
}
示例4: Apply
public void Apply(BsonClassMap classMap)
{
if (classMap.ClassType.IsClass && typeof(ISaga).IsAssignableFrom(classMap.ClassType))
{
classMap.MapIdProperty(nameof(ISaga.CorrelationId));
}
}
示例5: BsonMigrationSerializer
public BsonMigrationSerializer(IBsonSerializer versionSerializer, IVersionDetectionStrategy versionDetectionStrategy, BsonClassMap classMap)
: base(classMap)
{
_versionSerializer = versionSerializer;
_versionDetectionStrategy = versionDetectionStrategy;
_migrations = ExtractMigrations(classMap.ClassType);
}
示例6: TestSave
public void TestSave()
{
var server = Configuration.TestServer;
var database = Configuration.TestDatabase;
var collection = Configuration.GetTestCollection<Foo>();
var conventions = new ConventionPack();
conventions.Add(new NamedIdMemberConvention(new[] { "FooId" }));
ConventionRegistry.Register("test", conventions, t => t == typeof(Foo));
var classMap = new BsonClassMap<Foo>(cm => cm.AutoMap());
collection.RemoveAll();
for (int i = 0; i < 10; i++)
{
var foo = new Foo
{
FooId = ObjectId.Empty,
Name = string.Format("Foo-{0}", i),
Summary = string.Format("Summary for Foo-{0}", i)
};
collection.Save(foo);
var count = collection.Count();
Assert.AreEqual(i + 1, count);
}
}
示例7: ContentSerializer
public ContentSerializer(Type type, MongoDatabaseProvider database, IProxyFactory proxies)
{
this.database = database;
classMap = BsonClassMap.LookupClassMap(type);
serializer = new BsonClassMapSerializer(classMap);
this.proxies = proxies;
}
示例8: 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);
}
示例9: TestNamedIdMemberConventionWithTestClassB
public void TestNamedIdMemberConventionWithTestClassB()
{
var convention = new NamedIdMemberConvention("Id", "id", "_id");
var classMap = new BsonClassMap<TestClassB>();
convention.Apply(classMap);
Assert.Null(classMap.IdMemberMap);
}
示例10: Apply
// public methods
/// <summary>
/// Applies a modification to the class map.
/// </summary>
/// <param name="classMap">The class map.</param>
public void Apply(BsonClassMap classMap)
{
//使用插件机制处理序列化成员 james.wei 2015-05-26。
foreach (var convention in _conventions.OfType<IClassMapConvention>())
{
convention.Apply(classMap);
}
foreach (var convention in _conventions.OfType<IMemberMapConvention>())
{
foreach (var memberMap in classMap.DeclaredMemberMaps)
{
convention.Apply(memberMap);
}
}
foreach (var convention in _conventions.OfType<ICreatorMapConvention>())
{
foreach (var creatorMap in classMap.CreatorMaps)
{
convention.Apply(creatorMap);
}
}
foreach (var convention in _conventions.OfType<IPostProcessingConvention>())
{
convention.PostProcess(classMap);
}
}
示例11: PostProcess
/// <summary>
/// Post process the class map.
/// </summary>
/// <param name="classMap">The class map to be processed.</param>
public void PostProcess(BsonClassMap classMap)
{
if (typeof(IEntity).IsAssignableFrom(classMap.ClassType) && classMap.IdMemberMap != null)
{
classMap.IdMemberMap.SetIdGenerator(new GuidGenerator());
}
}
示例12: MongoTest
static MongoTest()
{
BsonSerializer.RegisterIdGenerator(typeof(string), StringObjectIdGenerator.Instance);
var map = new BsonClassMap<Person>();
map.AutoMap();
BsonClassMap.RegisterClassMap(map);
}
示例13: TestIsReadOnlyPropertyOfAField
public void TestIsReadOnlyPropertyOfAField()
{
var classMap = new BsonClassMap<TestClass>(cm => cm.AutoMap());
var memberMap = classMap.GetMemberMap("Field");
Assert.IsFalse(memberMap.IsReadOnly);
}
示例14: BsonMemberMap
// constructors
/// <summary>
/// Initializes a new instance of the BsonMemberMap class.
/// </summary>
/// <param name="classMap">The class map this member map belongs to.</param>
/// <param name="memberInfo">The member info.</param>
public BsonMemberMap(BsonClassMap classMap, MemberInfo memberInfo)
{
_classMap = classMap;
_memberInfo = memberInfo;
_memberType = BsonClassMap.GetMemberInfoType(memberInfo);
_defaultValue = GetDefaultValue(_memberType);
}
示例15: SetUp
public void SetUp()
{
var stopwatch = new Stopwatch();
_pack = new ConventionPack();
_pack.AddRange(new IConvention[]
{
new TrackingBeforeConvention(stopwatch) { Name = "1" },
new TrackingMemberConvention(stopwatch) { Name = "3" },
new TrackingAfterConvention(stopwatch) { Name = "5" },
new TrackingMemberConvention(stopwatch) { Name = "4" },
new TrackingAfterConvention(stopwatch) { Name = "6" },
new TrackingBeforeConvention(stopwatch) { Name = "2" },
});
_subject = new ConventionRunner(_pack);
var classMap = new BsonClassMap<TestClass>(cm =>
{
cm.MapMember(t => t.Prop1);
cm.MapMember(t => t.Prop2);
});
stopwatch.Start();
_subject.Apply(classMap);
stopwatch.Stop();
}