Пример #1
0
        public static T DeserializePayloadUsingSpecificSerializer <T>(
            this DescribedSerializationBase describedSerializationBase,
            IDeserialize deserializer,
            AssemblyMatchStrategy assemblyMatchStrategy = AssemblyMatchStrategy.AnySingleVersion)
        {
            var result = (T)DeserializePayloadUsingSpecificSerializer(describedSerializationBase, deserializer, assemblyMatchStrategy);

            return(result);
        }
Пример #2
0
        public static object DeserializePayloadUsingSpecificSerializer(
            this DescribedSerializationBase describedSerializationBase,
            IDeserialize deserializer,
            AssemblyMatchStrategy assemblyMatchStrategy = AssemblyMatchStrategy.AnySingleVersion)
        {
            if (describedSerializationBase == null)
            {
                throw new ArgumentNullException(nameof(describedSerializationBase));
            }

            if (deserializer == null)
            {
                throw new ArgumentNullException(nameof(deserializer));
            }

            var targetType = describedSerializationBase.PayloadTypeRepresentation.ResolveFromLoadedTypes(assemblyMatchStrategy);

            object result;

            var serializationFormat = describedSerializationBase.GetSerializationFormat();

            switch (serializationFormat)
            {
            case SerializationFormat.Binary:
                var describedSerializationBinary = (BinaryDescribedSerialization)describedSerializationBase;
                var serializedBytes = describedSerializationBinary.SerializedPayload;
                result = serializedBytes == null ? null : deserializer.Deserialize(serializedBytes, targetType);
                break;

            case SerializationFormat.String:
                var describedSerializationString = (StringDescribedSerialization)describedSerializationBase;
                var serializedString             = describedSerializationString.SerializedPayload;
                result = serializedString == null ? null : deserializer.Deserialize(serializedString, targetType);
                break;

            default:
                throw new NotSupportedException(Invariant($"{nameof(SerializationFormat)} - {serializationFormat} is not supported."));
            }

            return(result);
        }
Пример #3
0
        /// <summary>
        /// Converts a self described serialization back into it's object.
        /// </summary>
        /// <param name="describedSerializationBase">Self described serialized object.</param>
        /// <param name="serializerFactory">Implementation of <see cref="ISerializerFactory" /> that can resolve the serializer.</param>
        /// <param name="assemblyMatchStrategy">Optional assembly match strategy for resolving the type of object as well as the configuration type if any; DEFAULT is <see cref="AssemblyMatchStrategy.AnySingleVersion" />.</param>
        /// <returns>
        /// Originally serialized object.
        /// </returns>
        public static object DeserializePayloadUsingSpecificFactory(
            this DescribedSerializationBase describedSerializationBase,
            ISerializerFactory serializerFactory,
            AssemblyMatchStrategy assemblyMatchStrategy = AssemblyMatchStrategy.AnySingleVersion)
        {
            if (describedSerializationBase == null)
            {
                throw new ArgumentNullException(nameof(describedSerializationBase));
            }

            if (serializerFactory == null)
            {
                throw new ArgumentNullException(nameof(serializerFactory));
            }

            var serializer = serializerFactory.BuildSerializer(describedSerializationBase.SerializerRepresentation, assemblyMatchStrategy);

            var result = describedSerializationBase.DeserializePayloadUsingSpecificSerializer(serializer, assemblyMatchStrategy);

            return(result);
        }