예제 #1
0
        /// <summary>
        /// Sets the default serialization
        /// </summary>
        /// <param name="serializationDescriptor"><see cref="SerializationDescriptor"/> of the <see cref="ISerializer"/> to use as the default</param>
        public void SetDefaultSerializer(SerializationDescriptor serializationDescriptor)
        {
            var serializer = serializers.SingleOrDefault(s => s.Descriptor == serializationDescriptor);

            if (serializer is null)
            {
                throw new InvalidOperationException($"No matching serializer for {serializationDescriptor.InvariantName} found in the cache");
            }

            DefaultSerializer = serializer;
        }
예제 #2
0
 /// <summary>
 /// Tries to retrieve a <see cref="ISerializer"/> from the cache where the <see cref="ISerializer.Descriptor"/>'s name matches the supplied name
 /// </summary>
 /// <param name="descriptor"><see cref="SerializationDescriptor"/> of the <see cref="ISerializer"/> to retrieve from the cache</param>
 /// <param name="serializer">Out <see cref="ISerializer"/></param>
 /// <returns>true if the cache contains a matching <see cref="ISerializer"/>; false otherwise</returns>
 public bool SerializerFor(SerializationDescriptor descriptor, out ISerializer serializer)
 {
     serializer = serializers.SingleOrDefault(s => s.Descriptor == descriptor);
     return(!(serializer is null));
 }