Adding TextPlainFormatter to always handle returning strings as text\pla...

One Functional test will be added after #849
1. We are not going to call it produces content
2. I think the behavior is still correct. You can explicitly set the formatter or remove the textplain formatter to ignore it.
3. I think it needs to support more types than just string. Stringbuilder comes to mind. Not sure if we want other types as well, textwriter? 

-----Original Message-----
From: "Harsh Gupta" <notifications@github.com>
Sent: ‎7/‎27/‎2014 5:17 PM
To: "aspnet/Mvc" <Mvc@noreply.github.com>
Cc: "Yishai Galatzer" <yishai_galatzer@yahoo.com>
Subject: Re: [Mvc] Adding TextPlainFormatter to always handle returningstrings as text\pla... (#868)

In src/Microsoft.AspNet.Mvc.Core/Formatters/TextPlainFormatter.cs:
> +namespace Microsoft.AspNet.Mvc
> +{
> +    /// <summary>
> +    /// Writes a string value to the response.
> +    /// </summary>
> +    public class TextPlainFormatter : OutputFormatter
> +    {
> +        public TextPlainFormatter()
> +        {
> +            SupportedMediaTypes.Add(MediaTypeHeaderValue.Parse("text/plain"));
> +            SupportedEncodings.Add(Encoding.GetEncoding("utf-8"));
> +        }
> +        
> +        public override bool CanWriteResult(OutputFormatterContext context, MediaTypeHeaderValue contentType)
> +        {
> +            if (base.CanWriteResult(context, contentType))
Orthogonal to Pranav's comment, with the current implementation this is going to participate in content negotiation, if accept header or content type (set by using ProducesContent attr) is set. Now as per my discussion with @yishaigalatzer we want to always return text/plain format if the object is a string. However this means that if some action (or class ) had a 
[ProducesContent("application/json")]
then the produces content attribute gets ignored which in my opinion is not right. 
@yishaigalatzer thoughts?
—
Reply to this email directly or view it on GitHub.