Mongo.Context.MongoMetadata.AddDocumentType C# (CSharp) Method

AddDocumentType() private method

private AddDocumentType ( MongoContext context, string collectionName, BsonDocument document, ResourceTypeKind resourceTypeKind ) : System.Data.Services.Providers.ResourceType
context MongoContext
collectionName string
document BsonDocument
resourceTypeKind ResourceTypeKind
return System.Data.Services.Providers.ResourceType
        private ResourceType AddDocumentType(MongoContext context, string collectionName, BsonDocument document, ResourceTypeKind resourceTypeKind)
        {
            var collectionType = resourceTypeKind == ResourceTypeKind.EntityType
                                     ? this.instanceMetadataCache.AddEntityType(collectionName)
                                     : this.instanceMetadataCache.AddComplexType(collectionName);

            bool hasObjectId = false;
            if (document != null)
            {
                foreach (var element in document.Elements)
                {
                    RegisterResourceProperty(context, collectionType, element);
                    if (IsObjectId(element))
                        hasObjectId = true;
                }
            }

            if (!hasObjectId)
            {
                if (resourceTypeKind == ResourceTypeKind.EntityType)
                {
                    this.instanceMetadataCache.AddKeyProperty(collectionType, MappedObjectIdName, MappedObjectIdType);
                }
                AddProviderType(collectionName, ProviderObjectIdName, BsonObjectId.Empty, true);
            }

            if (resourceTypeKind == ResourceTypeKind.EntityType)
                this.instanceMetadataCache.AddResourceSet(collectionName, collectionType);

            return collectionType;
        }