MongoDB.Bson.Serialization.Attributes.BsonSerializerAttribute.CreateSerializer C# (CSharp) Метод

CreateSerializer() приватный Метод

Creates a serializer for a type based on the serializer type specified by the attribute.
private CreateSerializer ( Type type ) : IBsonSerializer
type System.Type The type that a serializer should be created for.
Результат IBsonSerializer
        internal IBsonSerializer CreateSerializer(Type type)
        {
            if (type.ContainsGenericParameters)
            {
                var message = "Cannot create a serializer because the type to serialize is an open generic type.";
                throw new InvalidOperationException(message);
            }

            if (_serializerType.ContainsGenericParameters && !type.IsGenericType)
            {
                var message = "Cannot create a serializer because the serializer type is an open generic type and the type to serialize is not generic.";
                throw new InvalidOperationException(message);
            }

            if (_serializerType.ContainsGenericParameters)
            {
                var genericArguments = type.GetGenericArguments();
                var closedSerializerType = _serializerType.MakeGenericType(genericArguments);
                return (IBsonSerializer)Activator.CreateInstance(closedSerializerType);
            }
            else
            {
                return (IBsonSerializer)Activator.CreateInstance(_serializerType);
            }
        }
    }