protected override void WriteTo(object item, TextWriter writer, WriterContext context)
        {
            if (item == null)
            {
                return;
            }

            FormUrlEncodingSerializer serializer = new FormUrlEncodingSerializer(item.GetType());

            serializer.Serialize(writer, item, context.Session.SerializerSettings);
        }
Esempio n. 2
0
 public void WriteTo(object entity, OpenRasta.Web.IHttpEntity response, string[] codecParameters)
 {
     using (TextWriter writer = new StreamWriter(response.Stream))
     {
         Encoding enc = null;
         if (Context.Request.Headers["Accept-Charset"] != null)
         {
             enc = Encoding.GetEncoding(Context.Request.Headers["Accept-Charset"]);
         }
         ObjectSerializerSettings settings = new ObjectSerializerSettings {
             Encoding = enc
         };
         FormUrlEncodingSerializer serializer = new FormUrlEncodingSerializer(entity.GetType());
         serializer.Serialize(writer, entity, settings);
     }
 }
        protected T Deserialize <T>(string s, string charset = null)
            where T : class
        {
            FormUrlEncodingSerializer serializer = new FormUrlEncodingSerializer(typeof(T));

            s = s.Replace("\r", "");
            s = s.Replace("\n", "");

            using (TextReader reader = new StringReader(s))
            {
                Encoding enc  = (charset != null ? Encoding.GetEncoding(charset) : null);
                T        data = (T)serializer.Deserialize(reader, new ObjectSerializerSettings {
                    Encoding = enc
                });
                return(data);
            }
        }
        protected override object ReadFrom(TextReader reader, ReaderContext context)
        {
            FormUrlEncodingSerializer serializer = new FormUrlEncodingSerializer(context.DataType);

            return(serializer.Deserialize(reader, context.Session.SerializerSettings));
        }