MongoDB.Bson.Serialization.Conventions.LookupIdGeneratorConvention.PostProcess C# (CSharp) Method

PostProcess() public method

Applies a post processing modification to the class map.
public PostProcess ( BsonClassMap classMap ) : void
classMap BsonClassMap The class map.
return void
        public void PostProcess(BsonClassMap classMap)
        {
            var idMemberMap = classMap.IdMemberMap;
            if (idMemberMap != null)
            {
                if (idMemberMap.IdGenerator == null)
                {
                    var idGenerator = BsonSerializer.LookupIdGenerator(idMemberMap.MemberType);
                    if (idGenerator != null)
                    {
                        idMemberMap.SetIdGenerator(idGenerator);
                    }
                }
            }
        }

Usage Example

 public void TestLookupIdGeneratorConventionWithTestClassB()
 {
     var convention = new LookupIdGeneratorConvention();
     var classMap = new BsonClassMap<TestClassB>();
     classMap.MapIdMember(x => x.GuidId);
     convention.PostProcess(classMap);
     Assert.IsNotNull(classMap.IdMemberMap.IdGenerator);
     Assert.IsInstanceOf<GuidGenerator>(classMap.IdMemberMap.IdGenerator);
 }
All Usage Examples Of MongoDB.Bson.Serialization.Conventions.LookupIdGeneratorConvention::PostProcess
LookupIdGeneratorConvention