diff --git a/src/Html/Abstractions/ref/Microsoft.AspNetCore.Html.Abstractions.csproj b/src/Html/Abstractions/ref/Microsoft.AspNetCore.Html.Abstractions.csproj index e27f9b24159b..2b1b278a3ff3 100644 --- a/src/Html/Abstractions/ref/Microsoft.AspNetCore.Html.Abstractions.csproj +++ b/src/Html/Abstractions/ref/Microsoft.AspNetCore.Html.Abstractions.csproj @@ -2,6 +2,7 @@ $(DefaultNetCoreTargetFramework) + annotations diff --git a/src/Html/Abstractions/ref/Microsoft.AspNetCore.Html.Abstractions.netcoreapp.cs b/src/Html/Abstractions/ref/Microsoft.AspNetCore.Html.Abstractions.netcoreapp.cs index 206b2611d192..389c89c233ad 100644 --- a/src/Html/Abstractions/ref/Microsoft.AspNetCore.Html.Abstractions.netcoreapp.cs +++ b/src/Html/Abstractions/ref/Microsoft.AspNetCore.Html.Abstractions.netcoreapp.cs @@ -3,15 +3,16 @@ namespace Microsoft.AspNetCore.Html { + [System.Diagnostics.DebuggerDisplayAttribute("{DebuggerToString()}")] public partial class HtmlContentBuilder : Microsoft.AspNetCore.Html.IHtmlContent, Microsoft.AspNetCore.Html.IHtmlContentBuilder, Microsoft.AspNetCore.Html.IHtmlContentContainer { public HtmlContentBuilder() { } public HtmlContentBuilder(System.Collections.Generic.IList entries) { } public HtmlContentBuilder(int capacity) { } public int Count { get { throw null; } } - public Microsoft.AspNetCore.Html.IHtmlContentBuilder Append(string unencoded) { throw null; } - public Microsoft.AspNetCore.Html.IHtmlContentBuilder AppendHtml(Microsoft.AspNetCore.Html.IHtmlContent htmlContent) { throw null; } - public Microsoft.AspNetCore.Html.IHtmlContentBuilder AppendHtml(string encoded) { throw null; } + public Microsoft.AspNetCore.Html.IHtmlContentBuilder Append(string? unencoded) { throw null; } + public Microsoft.AspNetCore.Html.IHtmlContentBuilder AppendHtml(Microsoft.AspNetCore.Html.IHtmlContent? htmlContent) { throw null; } + public Microsoft.AspNetCore.Html.IHtmlContentBuilder AppendHtml(string? encoded) { throw null; } public Microsoft.AspNetCore.Html.IHtmlContentBuilder Clear() { throw null; } public void CopyTo(Microsoft.AspNetCore.Html.IHtmlContentBuilder destination) { } public void MoveTo(Microsoft.AspNetCore.Html.IHtmlContentBuilder destination) { } @@ -32,7 +33,7 @@ public static partial class HtmlContentBuilderExtensions [System.Diagnostics.DebuggerDisplayAttribute("{DebuggerToString()}")] public partial class HtmlFormattableString : Microsoft.AspNetCore.Html.IHtmlContent { - public HtmlFormattableString(System.IFormatProvider formatProvider, string format, params object[] args) { } + public HtmlFormattableString(System.IFormatProvider? formatProvider, string format, params object[] args) { } public HtmlFormattableString(string format, params object[] args) { } public void WriteTo(System.IO.TextWriter writer, System.Text.Encodings.Web.HtmlEncoder encoder) { } } @@ -40,8 +41,8 @@ public partial class HtmlString : Microsoft.AspNetCore.Html.IHtmlContent { public static readonly Microsoft.AspNetCore.Html.HtmlString Empty; public static readonly Microsoft.AspNetCore.Html.HtmlString NewLine; - public HtmlString(string value) { } - public string Value { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } } + public HtmlString(string? value) { } + public string? Value { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } } public override string ToString() { throw null; } public void WriteTo(System.IO.TextWriter writer, System.Text.Encodings.Web.HtmlEncoder encoder) { } } diff --git a/src/Html/Abstractions/src/HtmlContentBuilder.cs b/src/Html/Abstractions/src/HtmlContentBuilder.cs index e61d9f7dc861..626dfcea984a 100644 --- a/src/Html/Abstractions/src/HtmlContentBuilder.cs +++ b/src/Html/Abstractions/src/HtmlContentBuilder.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.IO; using System.Text.Encodings.Web; @@ -11,6 +12,7 @@ namespace Microsoft.AspNetCore.Html /// /// An implementation using an in memory list. /// + [DebuggerDisplay("{DebuggerToString()}")] public class HtmlContentBuilder : IHtmlContentBuilder { /// @@ -61,7 +63,7 @@ public HtmlContentBuilder(IList entries) internal IList Entries { get; } /// - public IHtmlContentBuilder Append(string unencoded) + public IHtmlContentBuilder Append(string? unencoded) { if (!string.IsNullOrEmpty(unencoded)) { @@ -72,7 +74,7 @@ public IHtmlContentBuilder Append(string unencoded) } /// - public IHtmlContentBuilder AppendHtml(IHtmlContent htmlContent) + public IHtmlContentBuilder AppendHtml(IHtmlContent? htmlContent) { if (htmlContent == null) { @@ -84,7 +86,7 @@ public IHtmlContentBuilder AppendHtml(IHtmlContent htmlContent) } /// - public IHtmlContentBuilder AppendHtml(string encoded) + public IHtmlContentBuilder AppendHtml(string? encoded) { if (!string.IsNullOrEmpty(encoded)) { @@ -113,13 +115,11 @@ public void CopyTo(IHtmlContentBuilder destination) { var entry = Entries[i]; - string entryAsString; - IHtmlContentContainer entryAsContainer; - if ((entryAsString = entry as string) != null) + if (entry is string entryAsString) { destination.Append(entryAsString); } - else if ((entryAsContainer = entry as IHtmlContentContainer) != null) + else if (entry is IHtmlContentContainer entryAsContainer) { // Since we're copying, do a deep flatten. entryAsContainer.CopyTo(destination); @@ -144,13 +144,11 @@ public void MoveTo(IHtmlContentBuilder destination) { var entry = Entries[i]; - string entryAsString; - IHtmlContentContainer entryAsContainer; - if ((entryAsString = entry as string) != null) + if (entry is string entryAsString) { destination.Append(entryAsString); } - else if ((entryAsContainer = entry as IHtmlContentContainer) != null) + else if (entry is IHtmlContentContainer entryAsContainer) { // Since we're moving, do a deep flatten. entryAsContainer.MoveTo(destination); @@ -197,11 +195,9 @@ public void WriteTo(TextWriter writer, HtmlEncoder encoder) private string DebuggerToString() { - using (var writer = new StringWriter()) - { - WriteTo(writer, HtmlEncoder.Default); - return writer.ToString(); - } + using var writer = new StringWriter(); + WriteTo(writer, HtmlEncoder.Default); + return writer.ToString(); } } } diff --git a/src/Html/Abstractions/src/HtmlFormattableString.cs b/src/Html/Abstractions/src/HtmlFormattableString.cs index 24bc7c5e2f95..f69c9768631a 100644 --- a/src/Html/Abstractions/src/HtmlFormattableString.cs +++ b/src/Html/Abstractions/src/HtmlFormattableString.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// 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; @@ -39,7 +39,7 @@ public HtmlFormattableString(string format, params object[] args) /// An object that provides culture-specific formatting information. /// A composite format string. /// An array that contains objects to format. - public HtmlFormattableString(IFormatProvider formatProvider, string format, params object[] args) + public HtmlFormattableString(IFormatProvider? formatProvider, string format, params object[] args) { if (format == null) { @@ -94,7 +94,7 @@ private class EncodingFormatProvider : IFormatProvider, ICustomFormatter private readonly HtmlEncoder _encoder; private readonly IFormatProvider _formatProvider; - private StringWriter _writer; + private StringWriter? _writer; public EncodingFormatProvider(IFormatProvider formatProvider, HtmlEncoder encoder) { @@ -105,7 +105,7 @@ public EncodingFormatProvider(IFormatProvider formatProvider, HtmlEncoder encode _encoder = encoder; } - public string Format(string format, object arg, IFormatProvider formatProvider) + public string Format(string? format, object? arg, IFormatProvider? formatProvider) { // These are the cases we need to special case. We trust the HtmlString or IHtmlContent instance // to do the right thing with encoding. @@ -118,7 +118,7 @@ public string Format(string format, object arg, IFormatProvider formatProvider) var htmlContent = arg as IHtmlContent; if (htmlContent != null) { - _writer = _writer ?? new StringWriter(); + _writer ??= new StringWriter(); htmlContent.WriteTo(_writer, _encoder); @@ -133,7 +133,7 @@ public string Format(string format, object arg, IFormatProvider formatProvider) // // First check for an ICustomFormatter - if the IFormatProvider is a CultureInfo, then it's likely // that ICustomFormatter will be null. - var customFormatter = (ICustomFormatter)_formatProvider.GetFormat(typeof(ICustomFormatter)); + var customFormatter = (ICustomFormatter?)_formatProvider.GetFormat(typeof(ICustomFormatter)); if (customFormatter != null) { var result = customFormatter.Format(format, arg, _formatProvider); @@ -170,7 +170,7 @@ public string Format(string format, object arg, IFormatProvider formatProvider) return string.Empty; } - public object GetFormat(Type formatType) + public object? GetFormat(Type? formatType) { if (formatType == typeof(ICustomFormatter)) { diff --git a/src/Html/Abstractions/src/HtmlString.cs b/src/Html/Abstractions/src/HtmlString.cs index e7a516bd0468..888ba4497352 100644 --- a/src/Html/Abstractions/src/HtmlString.cs +++ b/src/Html/Abstractions/src/HtmlString.cs @@ -26,7 +26,7 @@ public class HtmlString : IHtmlContent /// Creates a new . /// /// The HTML encoded value. - public HtmlString(string value) + public HtmlString(string? value) { Value = value; } @@ -34,7 +34,7 @@ public HtmlString(string value) /// /// Gets the HTML encoded value. /// - public string Value { get; } + public string? Value { get; } /// public void WriteTo(TextWriter writer, HtmlEncoder encoder) diff --git a/src/Html/Abstractions/src/Microsoft.AspNetCore.Html.Abstractions.csproj b/src/Html/Abstractions/src/Microsoft.AspNetCore.Html.Abstractions.csproj index 0fce64a89d14..9f3710febf4c 100644 --- a/src/Html/Abstractions/src/Microsoft.AspNetCore.Html.Abstractions.csproj +++ b/src/Html/Abstractions/src/Microsoft.AspNetCore.Html.Abstractions.csproj @@ -1,4 +1,4 @@ - + ASP.NET Core HTML abstractions used for building HTML content. @@ -11,6 +11,7 @@ Microsoft.AspNetCore.Html.IHtmlContent true aspnetcore false + enable diff --git a/src/Html/Abstractions/test/HtmlContentBuilderTest.cs b/src/Html/Abstractions/test/HtmlContentBuilderTest.cs index c3cb7d1954a9..22823375dc73 100644 --- a/src/Html/Abstractions/test/HtmlContentBuilderTest.cs +++ b/src/Html/Abstractions/test/HtmlContentBuilderTest.cs @@ -256,7 +256,7 @@ public override int GetHashCode() return _content.GetHashCode(); } - public override bool Equals(object obj) + public override bool Equals(object? obj) { var other = obj as TestHtmlContent; if (other != null) @@ -267,9 +267,9 @@ public override bool Equals(object obj) return base.Equals(obj); } - public bool Equals(TestHtmlContent other) + public bool Equals(TestHtmlContent? other) { - return string.Equals(_content, other._content); + return other != null && string.Equals(_content, other._content); } } } diff --git a/src/Html/Abstractions/test/Microsoft.AspNetCore.Html.Abstractions.Tests.csproj b/src/Html/Abstractions/test/Microsoft.AspNetCore.Html.Abstractions.Tests.csproj index 849d9f5bf11d..0c9196c21f87 100644 --- a/src/Html/Abstractions/test/Microsoft.AspNetCore.Html.Abstractions.Tests.csproj +++ b/src/Html/Abstractions/test/Microsoft.AspNetCore.Html.Abstractions.Tests.csproj @@ -2,6 +2,7 @@ $(DefaultNetCoreTargetFramework) + enable