diff --git a/src/Shared/RazorViews/AttributeValue.cs b/src/Shared/RazorViews/AttributeValue.cs deleted file mode 100644 index 7a066a7040..0000000000 --- a/src/Shared/RazorViews/AttributeValue.cs +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; - -namespace Microsoft.Extensions.RazorViews -{ - internal class AttributeValue - { - public AttributeValue(string prefix, object value, bool literal) - { - Prefix = prefix; - Value = value; - Literal = literal; - } - - public string Prefix { get; } - - public object Value { get; } - - public bool Literal { get; } - - public static AttributeValue FromTuple(Tuple value) - { - return new AttributeValue(value.Item1, value.Item2, value.Item3); - } - - public static AttributeValue FromTuple(Tuple value) - { - return new AttributeValue(value.Item1, value.Item2, value.Item3); - } - - public static implicit operator AttributeValue(Tuple value) - { - return FromTuple(value); - } - } -} \ No newline at end of file diff --git a/src/Shared/RazorViews/BaseView.cs b/src/Shared/RazorViews/BaseView.cs deleted file mode 100644 index a171d8d1f2..0000000000 --- a/src/Shared/RazorViews/BaseView.cs +++ /dev/null @@ -1,279 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Globalization; -using System.IO; -using System.Linq; -using System.Text; -using System.Text.Encodings.Web; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Http; - -namespace Microsoft.Extensions.RazorViews -{ - /// - /// Infrastructure - /// - internal abstract class BaseView - { - private static readonly Encoding UTF8NoBOM = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false, throwOnInvalidBytes: true); - private readonly Stack _textWriterStack = new Stack(); - - /// - /// The request context - /// - protected HttpContext Context { get; private set; } - - /// - /// The request - /// - protected HttpRequest Request { get; private set; } - - /// - /// The response - /// - protected HttpResponse Response { get; private set; } - - /// - /// The output stream - /// - protected TextWriter Output { get; private set; } - - /// - /// Html encoder used to encode content. - /// - protected HtmlEncoder HtmlEncoder { get; set; } = HtmlEncoder.Default; - - /// - /// Url encoder used to encode content. - /// - protected UrlEncoder UrlEncoder { get; set; } = UrlEncoder.Default; - - /// - /// JavaScript encoder used to encode content. - /// - protected JavaScriptEncoder JavaScriptEncoder { get; set; } = JavaScriptEncoder.Default; - - /// - /// Execute an individual request - /// - /// - public async Task ExecuteAsync(HttpContext context) - { - Context = context; - Request = Context.Request; - Response = Context.Response; - Output = new StreamWriter(Response.Body, UTF8NoBOM, 4096, leaveOpen: true); - await ExecuteAsync(); - Output.Dispose(); - } - - /// - /// Execute an individual request - /// - public abstract Task ExecuteAsync(); - - protected virtual void PushWriter(TextWriter writer) - { - if (writer == null) - { - throw new ArgumentNullException(nameof(writer)); - } - - _textWriterStack.Push(Output); - Output = writer; - } - - protected virtual TextWriter PopWriter() - { - Output = _textWriterStack.Pop(); - return Output; - } - - /// - /// Write the given value without HTML encoding directly to . - /// - /// The to write. - protected void WriteLiteral(object value) - { - WriteLiteral(Convert.ToString(value, CultureInfo.InvariantCulture)); - } - - /// - /// Write the given value without HTML encoding directly to . - /// - /// The to write. - protected void WriteLiteral(string value) - { - if (!string.IsNullOrEmpty(value)) - { - Output.Write(value); - } - } - - private List AttributeValues { get; set; } - - protected void WriteAttributeValue(string thingy, int startPostion, object value, int endValue, int dealyo, bool yesno) - { - if (AttributeValues == null) - { - AttributeValues = new List(); - } - - AttributeValues.Add(value.ToString()); - } - - private string AttributeEnding { get; set; } - - protected void BeginWriteAttribute(string name, string begining, int startPosition, string ending, int endPosition, int thingy) - { - Debug.Assert(string.IsNullOrEmpty(AttributeEnding)); - - Output.Write(begining); - AttributeEnding = ending; - } - - protected void EndWriteAttribute() - { - Debug.Assert(!string.IsNullOrEmpty(AttributeEnding)); - - var attributes = string.Join(" ", AttributeValues); - Output.Write(attributes); - AttributeValues = null; - - Output.Write(AttributeEnding); - AttributeEnding = null; - } - - /// - /// Writes the given attribute to the given writer - /// - /// The name of the attribute to write - /// The value of the prefix - /// The value of the suffix - /// The s to write. - protected void WriteAttribute( - string name, - string leader, - string trailer, - params AttributeValue[] values) - { - if (name == null) - { - throw new ArgumentNullException(nameof(name)); - } - - if (leader == null) - { - throw new ArgumentNullException(nameof(leader)); - } - - if (trailer == null) - { - throw new ArgumentNullException(nameof(trailer)); - } - - WriteLiteral(leader); - foreach (var value in values) - { - WriteLiteral(value.Prefix); - - // The special cases here are that the value we're writing might already be a string, or that the - // value might be a bool. If the value is the bool 'true' we want to write the attribute name - // instead of the string 'true'. If the value is the bool 'false' we don't want to write anything. - // Otherwise the value is another object (perhaps an HtmlString) and we'll ask it to format itself. - string stringValue; - if (value.Value is bool) - { - if ((bool)value.Value) - { - stringValue = name; - } - else - { - continue; - } - } - else - { - stringValue = value.Value as string; - } - - // Call the WriteTo(string) overload when possible - if (value.Literal && stringValue != null) - { - WriteLiteral(stringValue); - } - else if (value.Literal) - { - WriteLiteral(value.Value); - } - else if (stringValue != null) - { - Write(stringValue); - } - else - { - Write(value.Value); - } - } - WriteLiteral(trailer); - } - - /// - /// is invoked - /// - /// The to invoke - protected void Write(HelperResult result) - { - Write(result); - } - - /// - /// Writes the specified to . - /// - /// The to write. - /// - /// is invoked for types. - /// For all other types, the encoded result of is written to - /// . - /// - protected void Write(object value) - { - if (value is HelperResult helperResult) - { - helperResult.WriteTo(Output); - } - else - { - Write(Convert.ToString(value, CultureInfo.InvariantCulture)); - } - } - - /// - /// Writes the specified with HTML encoding to . - /// - /// The to write. - protected void Write(string value) - { - WriteLiteral(HtmlEncoder.Encode(value)); - } - - protected string HtmlEncodeAndReplaceLineBreaks(string input) - { - if (string.IsNullOrEmpty(input)) - { - return string.Empty; - } - - // Split on line breaks before passing it through the encoder. - return string.Join("
" + Environment.NewLine, - input.Split(new[] { "\r\n" }, StringSplitOptions.None) - .SelectMany(s => s.Split(new[] { '\r', '\n' }, StringSplitOptions.None)) - .Select(HtmlEncoder.Encode)); - } - } -} \ No newline at end of file diff --git a/src/Shared/RazorViews/HelperResult.cs b/src/Shared/RazorViews/HelperResult.cs deleted file mode 100644 index c79944aae6..0000000000 --- a/src/Shared/RazorViews/HelperResult.cs +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.IO; - -namespace Microsoft.Extensions.RazorViews -{ - /// - /// Represents a deferred write operation in a . - /// - internal class HelperResult - { - /// - /// Creates a new instance of . - /// - /// The delegate to invoke when is called. - public HelperResult(Action action) - { - WriteAction = action; - } - - public Action WriteAction { get; } - - /// - /// Method invoked to produce content from the . - /// - /// The instance to write to. - public void WriteTo(TextWriter writer) - { - WriteAction(writer); - } - } -} \ No newline at end of file diff --git a/src/Shared/test/Shared.Tests/Microsoft.AspNetCore.Shared.Tests.csproj b/src/Shared/test/Shared.Tests/Microsoft.AspNetCore.Shared.Tests.csproj index 67ff52821b..014c17aba3 100644 --- a/src/Shared/test/Shared.Tests/Microsoft.AspNetCore.Shared.Tests.csproj +++ b/src/Shared/test/Shared.Tests/Microsoft.AspNetCore.Shared.Tests.csproj @@ -10,7 +10,6 @@