Created
March 6, 2012 22:50
-
-
Save darrelmiller/1989553 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class PlainTextFormatter : MediaTypeFormatter | |
{ | |
public PlainTextFormatter() | |
{ | |
SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/plain")); | |
} | |
protected override System.Threading.Tasks.Task<object> OnReadFromStreamAsync(Type type, System.IO.Stream stream, HttpContentHeaders contentHeaders, FormatterContext formatterContext) | |
{ | |
return new Task<object>(() => | |
{ | |
return new StreamReader(stream).ReadToEnd(); | |
}); | |
} | |
protected override Task OnWriteToStreamAsync(Type type, object value, Stream stream, HttpContentHeaders contentHeaders, FormatterContext formatterContext, System.Net.TransportContext transportContext) | |
{ | |
return new Task(() => | |
{ | |
var writer = new StreamWriter(stream); | |
writer.Write(value.ToString()); | |
}); | |
} | |
protected override bool CanReadType(Type type) | |
{ | |
return true; | |
} | |
protected override bool CanWriteType(Type type) | |
{ | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment