Esempio n. 1
0
 public void Can_serialize_null_object_to_Stream()
 {
     using (var ms = new MemoryStream())
     {
         JsonSerializer.SerializeToStream((object)null, ms);
         TypeSerializer.SerializeToStream((object)null, ms);
         XmlSerializer.SerializeToStream((object)null, ms);
     }
 }
        public sealed override object DeepCopyObject(object source)
        {
            if (source == null)
            {
                return(null);
            }

            var type = source.GetType();

            using (var ms = MemoryStreamManager.GetStream())
            {
                TypeSerializer.SerializeToStream(source, type, ms);
                ms.Seek(0, System.IO.SeekOrigin.Begin);
                return(TypeSerializer.DeserializeFromStream(type, ms));
            }
        }
Esempio n. 3
0
        private void SaveToDisk()
        {
            using (var iso = IsolatedStorageFile.GetUserStoreForApplication())
            {
                try
                {
                    if (iso.FileExists(Filename))
                    {
                        iso.DeleteFile(Filename);
                    }

                    using (var stream = iso.CreateFile(Filename))
                    {
                        TypeSerializer.SerializeToStream(Cache, stream);
                    }
                }
                catch (Exception ex)
                {
                    // todo: Log this somewhere...
                }
            }
        }
Esempio n. 4
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) => XmlSerializer.SerializeToStream(o, s);

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

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

            return null;
        }
Esempio n. 5
0
 public override void ParallelSerialize(object root, Stream stream)
 {
     TypeSerializer.SerializeToStream(root, m_primaryType, stream);
 }
Esempio n. 6
0
 private static void SerializeToStream(IRequestContext requestContext, object dto, Stream stream)
 {
     TypeSerializer.SerializeToStream(dto, stream);
 }
Esempio n. 7
0
 public static void SerializeToStream(object obj, Stream stream)
 {
     TypeSerializer.SerializeToStream(obj, obj.GetType(), stream);
 }
Esempio n. 8
0
 public override void SerializeToStream(IRequest requestContext, object request, Stream stream)
 {
     TypeSerializer.SerializeToStream(request, stream);
 }
 // Serialize using TypeSerializer.SerializeToStream(object, Type, Stream)
 public static string SerializeToStream2(IFoo item)
 {
     using var stream = new MemoryStream();
     TypeSerializer.SerializeToStream(item, item.GetType(), stream);
     return(Encoding.UTF8.GetString(stream.GetBuffer(), 0, (int)stream.Length));
 }
Esempio n. 10
0
 public override void Serialize(object serializable, Stream outputStream)
 {
     TypeSerializer.SerializeToStream(serializable, _primaryType, outputStream);
 }