Пример #1
0
        public static void Serialize(object data, Stream stream, DataFormat format)
        {
            switch (format)
            {
            case DataFormat.JSON:
                WrappedJsonSerializer.Instance.SerializeToStream(data, stream);
                break;

            case DataFormat.XML:
                WrappedXmlSerializer.SerializeToStream(data, stream);
                break;

            case DataFormat.ProtoBuf:
                Serializer.NonGeneric.Serialize(stream, data);
                break;

            case DataFormat.BJJSON:
                jsonSerializer.Serialize(data, stream);
                break;

            case DataFormat.BJBIN:
                binarySerializer.Serialize(data, stream);
                break;

            default:
                throw new NotSupportedException(format + " is not supported.");
            }
        }
Пример #2
0
        public StreamSerializerDelegate GetStreamSerializer(string contentType)
        {
            StreamSerializerDelegate responseWriter;

            if (this.ContentTypeSerializers.TryGetValue(contentType, out responseWriter) ||
                this.ContentTypeSerializers.TryGetValue(ContentType.GetRealContentType(contentType), out responseWriter))
            {
                return(responseWriter);
            }

            var contentTypeAttr = ContentType.GetEndpointAttributes(contentType);

            switch (contentTypeAttr)
            {
            case EndpointAttributes.Xml:
                return((r, o, s) => WrappedXmlSerializer.SerializeToStream(o, s));

            case EndpointAttributes.Json:
                return((r, o, s) => WrappedJsonSerializer.Instance.SerializeToStream(o, s));

            case EndpointAttributes.Jsv:
                return((r, o, s) => TypeSerializer.SerializeToStream(o, s));
            }

            return(null);
        }