private void AddResourceProperty(MongoContext context, string collectionName, ResourceType collectionType,
BsonElement element, bool treatObjectIdAsKey = false)
{
var elementType = GetElementType(element, treatObjectIdAsKey);
var propertyName = GetResourcePropertyName(element, collectionType.ResourceTypeKind);
var propertyValue = element.Value;
if (string.IsNullOrEmpty(propertyName))
return;
var isKey = false;
if (IsObjectId(element))
{
if (treatObjectIdAsKey)
this.instanceMetadataCache.AddKeyProperty(collectionType, propertyName, elementType);
else
this.instanceMetadataCache.AddPrimitiveProperty(collectionType, propertyName, elementType);
isKey = true;
}
else if (elementType == typeof(BsonDocument))
{
AddDocumentProperty(context, collectionName, collectionType, propertyName, element);
}
else if (elementType == typeof(BsonArray))
{
RegisterArrayProperty(context, collectionType, element);
}
else
{
this.instanceMetadataCache.AddPrimitiveProperty(collectionType, propertyName, elementType);
}
if (!string.IsNullOrEmpty(propertyName))
{
AddProviderType(collectionName, IsObjectId(element) ? ProviderObjectIdName : propertyName, propertyValue, isKey);
}
}