protected static Encoding CreateOrGetSupportedEncoding( TextOutputFormatter formatter, string encodingAsString, bool isDefaultEncoding) { Encoding encoding = null; if (isDefaultEncoding) { encoding = formatter .SupportedEncodings .First((e) => e.WebName.Equals(encodingAsString, StringComparison.OrdinalIgnoreCase)); } else { encoding = Encoding.GetEncoding(encodingAsString); formatter.SupportedEncodings.Add(encoding); } return(encoding); }
public void GetAcceptCharsetHeaderValues_ReadsHeaderAndParsesValues() { // Arrange const string expectedValue = "expected"; var formatter = new OverrideEncodingFormatter(encoding: null); var context = new DefaultHttpContext(); context.Request.Headers.AcceptCharset = expectedValue; var writerContext = new OutputFormatterWriteContext( context, new TestHttpResponseStreamWriterFactory().CreateWriter, objectType: null, @object: null); // Act var result = TextOutputFormatter.GetAcceptCharsetHeaderValues(writerContext); //Assert Assert.Equal(expectedValue, Assert.Single(result).Value.Value); }
/// <summary> /// Creates a new <see cref="XmlResultExecutor"/>. /// </summary> /// <param name="writerFactory">The <see cref="IHttpResponseStreamWriterFactory"/>.</param> /// <param name="loggerFactory">The <see cref="ILoggerFactory"/>.</param> /// <param name="outputFormatter">The <see cref="TextOutputFormatter"/>.</param> public XmlResultExecutorBase( IHttpResponseStreamWriterFactory writerFactory, ILoggerFactory loggerFactory, TextOutputFormatter outputFormatter) { if (writerFactory == null) { throw new ArgumentNullException(nameof(writerFactory)); } if (outputFormatter == null) { throw new ArgumentNullException(nameof(outputFormatter)); } if (loggerFactory == null) { throw new ArgumentNullException(nameof(loggerFactory)); } WriterFactory = writerFactory; Logger = loggerFactory.CreateLogger <XmlResult>(); OutputFormatter = outputFormatter; }
internal void build_method_body() { method_body = new List <string>(); var builder = new StringWriter(); var output = new PlainTextOutput(builder); var node = this.Declaration; var outputFormatter = new TextOutputFormatter(output) { FoldBraces = true }; var formattingPolicy = FormattingOptionsFactory.CreateAllman(); node.AcceptVisitor(new CppOutputVisitor(outputFormatter, formattingPolicy)); // string b = builder.ToString(); var bb = b.Replace("\r\n", "\n"); var bodylist = bb.Split('\n'); var tlist = new List <string>(); foreach (var item in bodylist) { var stat = item; tlist.Add(stat); } tlist.RemoveAt(0); // delete method define if (tlist.Count() > 0) { if (tlist[0].Trim() == "get" || tlist[0].Trim() == "set") { tlist.RemoveAt(0); } if (tlist[0].Trim() == "{") { tlist.RemoveAt(0); } while (tlist.Count() > 0) { if (tlist[tlist.Count() - 1].Trim() == "") { tlist.RemoveAt(tlist.Count() - 1); } else { break; } } if (tlist.Count() > 0) { if (tlist[tlist.Count() - 1].Trim() == "}") { tlist.RemoveAt(tlist.Count() - 1); } } } foreach (var s in tlist) { this.method_body.Add(s); } if (this.def.IsConstructor) { special_ctor(); special_init(); } else { special_tostring(); } }