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

GetElementType() private static method

private static GetElementType ( BsonElement element, bool treatObjectIdAsKey ) : Type
element BsonElement
treatObjectIdAsKey bool
return System.Type
        private static Type GetElementType(BsonElement element, bool treatObjectIdAsKey)
        {
            if (IsObjectId(element))
            {
                if (element.Value.GetType() == ProviderObjectIdType && treatObjectIdAsKey)
                    return MappedObjectIdType;
                else
                    return GetRawValueType(element.Value, treatObjectIdAsKey);
            }
            else if (element.Value.GetType() == typeof (BsonObjectId))
            {
                return MappedObjectIdType;
            }
            else if (element.Value.GetType() == typeof(BsonArray) || element.Value.GetType() == typeof(BsonDocument))
            {
                return element.Value.GetType();
            }
            else if (BsonTypeMapper.MapToDotNetValue(element.Value) != null)
            {
                return GetRawValueType(element.Value);
            }
            else
            {
                switch (element.Value.BsonType)
                {
                    case BsonType.Null:
                        return typeof(object);
                    case BsonType.Binary:
                        return typeof(byte[]);
                    default:
                        return typeof(string);
                }
            }
        }