public string Serialize(object model, string contentType, ModelFormatting formatting)
		{
			if (!Serializers.ContainsKey(contentType))
				throw new NotSupportedException(String.Format("Don't know how to serialize response with MIME type '{0}'", contentType));

			return Serializers[contentType].Serialize(model, formatting);
		}
        public string Serialize(object model, string contentType, ModelFormatting formatting)
        {
            if (!Serializers.ContainsKey(contentType))
            {
                throw new NotSupportedException(String.Format("Don't know how to serialize response with MIME type '{0}'", contentType));
            }

            return(Serializers[contentType].Serialize(model, formatting));
        }
Example #3
0
        public string Serialize(object model, ModelFormatting formatting)
        {
            using (var buffer = new MemoryStream(1024))
            using (var writer = new ModelXmlWriter(buffer, Encoding.UTF8, formatting))
            {
                DataContractSerializer serializer = GetSerializerForType(model.GetType());

                writer.WriteStartDocument();
                serializer.WriteObject(writer, model);
                writer.Flush();

                return Encoding.UTF8.GetString(buffer.ToArray());
            }
        }
Example #4
0
        public string Serialize(object model, ModelFormatting formatting)
        {
            using (var buffer = new MemoryStream(1024))
                using (var writer = new ModelXmlWriter(buffer, Encoding.UTF8, formatting))
                {
                    DataContractSerializer serializer = GetSerializerForType(model.GetType());

                    writer.WriteStartDocument();
                    serializer.WriteObject(writer, model);
                    writer.Flush();

                    return(Encoding.UTF8.GetString(buffer.ToArray()));
                }
        }
Example #5
0
		public ModelXmlWriter(Stream stream, Encoding encoding, ModelFormatting formatting)
			: base(stream, encoding)
		{
			Formatting = formatting == ModelFormatting.HumanReadable ? Formatting.Indented : Formatting.None;
		}
Example #6
0
		public string Serialize(object model, ModelFormatting formatting)
		{
			Formatting jsonFormatting = formatting == ModelFormatting.HumanReadable ? Formatting.Indented : Formatting.None;
			return JsonConvert.SerializeObject(model, jsonFormatting, Settings);
		}
Example #7
0
        public string Serialize(object model, ModelFormatting formatting)
        {
            Formatting jsonFormatting = formatting == ModelFormatting.HumanReadable ? Formatting.Indented : Formatting.None;

            return(JsonConvert.SerializeObject(model, jsonFormatting, Settings));
        }
Example #8
0
 public ModelXmlWriter(Stream stream, Encoding encoding, ModelFormatting formatting)
     : base(stream, encoding)
 {
     Formatting = formatting == ModelFormatting.HumanReadable ? Formatting.Indented : Formatting.None;
 }
Example #9
0
 public ModelResult(T model, ModelFormatting formatting, IModelSerializationService serializationService)
 {
     Model                = model;
     Formatting           = formatting;
     SerializationService = serializationService;
 }
Example #10
0
 public ModelResult(T model, ModelFormatting formatting)
     : this(model, formatting, ServiceLocator.Current.GetInstance <IModelSerializationService>())
 {
 }
Example #11
0
 public ModelResult <T> Model <T>(T model, ModelFormatting formatting)
 {
     return(new ModelResult <T>(model, formatting));
 }