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)); }
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()); } }
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())); } }
public ModelXmlWriter(Stream stream, Encoding encoding, ModelFormatting formatting) : base(stream, encoding) { Formatting = formatting == ModelFormatting.HumanReadable ? Formatting.Indented : Formatting.None; }
public string Serialize(object model, ModelFormatting formatting) { Formatting jsonFormatting = formatting == ModelFormatting.HumanReadable ? Formatting.Indented : Formatting.None; return JsonConvert.SerializeObject(model, jsonFormatting, Settings); }
public string Serialize(object model, ModelFormatting formatting) { Formatting jsonFormatting = formatting == ModelFormatting.HumanReadable ? Formatting.Indented : Formatting.None; return(JsonConvert.SerializeObject(model, jsonFormatting, Settings)); }
public ModelResult(T model, ModelFormatting formatting, IModelSerializationService serializationService) { Model = model; Formatting = formatting; SerializationService = serializationService; }
public ModelResult(T model, ModelFormatting formatting) : this(model, formatting, ServiceLocator.Current.GetInstance <IModelSerializationService>()) { }
public ModelResult <T> Model <T>(T model, ModelFormatting formatting) { return(new ModelResult <T>(model, formatting)); }