From e656fdf9534719531d574329a5877780c8177ba2 Mon Sep 17 00:00:00 2001 From: blouflashdb <45914736+blouflashdb@users.noreply.github.com> Date: Fri, 14 Oct 2022 20:55:15 +0200 Subject: [PATCH 1/2] add CompositeFormat StringSyntaxAttribute syntaxes --- src/Html.Abstractions/src/HtmlContentBuilderExtensions.cs | 4 +++- src/Html.Abstractions/src/HtmlFormattableString.cs | 8 ++++++-- src/Razor/Razor/src/TagHelpers/TagHelperContent.cs | 7 +++++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/Html.Abstractions/src/HtmlContentBuilderExtensions.cs b/src/Html.Abstractions/src/HtmlContentBuilderExtensions.cs index 53be2049e3d9..968db5a82a13 100644 --- a/src/Html.Abstractions/src/HtmlContentBuilderExtensions.cs +++ b/src/Html.Abstractions/src/HtmlContentBuilderExtensions.cs @@ -1,6 +1,8 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System.Diagnostics.CodeAnalysis; + namespace Microsoft.AspNetCore.Html; /// @@ -24,7 +26,7 @@ public static class HtmlContentBuilderExtensions /// A reference to this instance after the append operation has completed. public static IHtmlContentBuilder AppendFormat( this IHtmlContentBuilder builder, - string format, + [StringSyntax(StringSyntaxAttribute.CompositeFormat)] string format, params object?[] args) { if (builder == null) diff --git a/src/Html.Abstractions/src/HtmlFormattableString.cs b/src/Html.Abstractions/src/HtmlFormattableString.cs index 5bbc6219966a..0de6d6482b6a 100644 --- a/src/Html.Abstractions/src/HtmlFormattableString.cs +++ b/src/Html.Abstractions/src/HtmlFormattableString.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Text.Encodings.Web; @@ -25,7 +26,7 @@ public class HtmlFormattableString : IHtmlContent /// /// A composite format string. /// An array that contains objects to format. - public HtmlFormattableString(string format, params object?[] args) + public HtmlFormattableString([StringSyntax(StringSyntaxAttribute.CompositeFormat)] string format, params object?[] args) : this(formatProvider: null, format: format, args: args) { } @@ -37,7 +38,10 @@ 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, + [StringSyntax(StringSyntaxAttribute.CompositeFormat)] string format, + params object?[] args) { if (format == null) { diff --git a/src/Razor/Razor/src/TagHelpers/TagHelperContent.cs b/src/Razor/Razor/src/TagHelpers/TagHelperContent.cs index a8747b2bb101..25cc7eb7ad98 100644 --- a/src/Razor/Razor/src/TagHelpers/TagHelperContent.cs +++ b/src/Razor/Razor/src/TagHelpers/TagHelperContent.cs @@ -92,7 +92,7 @@ public TagHelperContent SetHtmlContent(string encoded) /// /// The object array to format. /// A reference to this instance after the append operation has completed. - public TagHelperContent AppendFormat(string format, params object[] args) + public TagHelperContent AppendFormat([StringSyntax(StringSyntaxAttribute.CompositeFormat)] string format, params object[] args) { HtmlContentBuilderExtensions.AppendFormat(this, null, format, args); return this; @@ -109,7 +109,10 @@ public TagHelperContent AppendFormat(string format, params object[] args) /// /// The object array to format. /// A reference to this instance after the append operation has completed. - public TagHelperContent AppendFormat(IFormatProvider provider, string format, params object[] args) + public TagHelperContent AppendFormat( + IFormatProvider provider, + [StringSyntax(StringSyntaxAttribute.CompositeFormat)] string format, + params object[] args) { HtmlContentBuilderExtensions.AppendFormat(this, provider, format, args); return this; From 7acab3813140e3ac85a03272eb29b962b9f92e48 Mon Sep 17 00:00:00 2001 From: blouflashdb <45914736+blouflashdb@users.noreply.github.com> Date: Fri, 14 Oct 2022 20:55:15 +0200 Subject: [PATCH 2/2] add CompositeFormat StringSyntaxAttribute syntaxes --- src/Html.Abstractions/src/HtmlContentBuilderExtensions.cs | 6 ++++-- src/Html.Abstractions/src/HtmlFormattableString.cs | 8 ++++++-- src/Razor/Razor/src/TagHelpers/TagHelperContent.cs | 8 ++++++-- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/Html.Abstractions/src/HtmlContentBuilderExtensions.cs b/src/Html.Abstractions/src/HtmlContentBuilderExtensions.cs index 53be2049e3d9..202893e162cf 100644 --- a/src/Html.Abstractions/src/HtmlContentBuilderExtensions.cs +++ b/src/Html.Abstractions/src/HtmlContentBuilderExtensions.cs @@ -1,6 +1,8 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System.Diagnostics.CodeAnalysis; + namespace Microsoft.AspNetCore.Html; /// @@ -24,7 +26,7 @@ public static class HtmlContentBuilderExtensions /// A reference to this instance after the append operation has completed. public static IHtmlContentBuilder AppendFormat( this IHtmlContentBuilder builder, - string format, + [StringSyntax(StringSyntaxAttribute.CompositeFormat)] string format, params object?[] args) { if (builder == null) @@ -64,7 +66,7 @@ public static IHtmlContentBuilder AppendFormat( public static IHtmlContentBuilder AppendFormat( this IHtmlContentBuilder builder, IFormatProvider formatProvider, - string format, + [StringSyntax(StringSyntaxAttribute.CompositeFormat)] string format, params object?[] args) { if (builder == null) diff --git a/src/Html.Abstractions/src/HtmlFormattableString.cs b/src/Html.Abstractions/src/HtmlFormattableString.cs index 5bbc6219966a..0de6d6482b6a 100644 --- a/src/Html.Abstractions/src/HtmlFormattableString.cs +++ b/src/Html.Abstractions/src/HtmlFormattableString.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Text.Encodings.Web; @@ -25,7 +26,7 @@ public class HtmlFormattableString : IHtmlContent /// /// A composite format string. /// An array that contains objects to format. - public HtmlFormattableString(string format, params object?[] args) + public HtmlFormattableString([StringSyntax(StringSyntaxAttribute.CompositeFormat)] string format, params object?[] args) : this(formatProvider: null, format: format, args: args) { } @@ -37,7 +38,10 @@ 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, + [StringSyntax(StringSyntaxAttribute.CompositeFormat)] string format, + params object?[] args) { if (format == null) { diff --git a/src/Razor/Razor/src/TagHelpers/TagHelperContent.cs b/src/Razor/Razor/src/TagHelpers/TagHelperContent.cs index a8747b2bb101..b528e63edf25 100644 --- a/src/Razor/Razor/src/TagHelpers/TagHelperContent.cs +++ b/src/Razor/Razor/src/TagHelpers/TagHelperContent.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System.Diagnostics.CodeAnalysis; using System.Text.Encodings.Web; using Microsoft.AspNetCore.Html; @@ -92,7 +93,7 @@ public TagHelperContent SetHtmlContent(string encoded) /// /// The object array to format. /// A reference to this instance after the append operation has completed. - public TagHelperContent AppendFormat(string format, params object[] args) + public TagHelperContent AppendFormat([StringSyntax(StringSyntaxAttribute.CompositeFormat)] string format, params object[] args) { HtmlContentBuilderExtensions.AppendFormat(this, null, format, args); return this; @@ -109,7 +110,10 @@ public TagHelperContent AppendFormat(string format, params object[] args) /// /// The object array to format. /// A reference to this instance after the append operation has completed. - public TagHelperContent AppendFormat(IFormatProvider provider, string format, params object[] args) + public TagHelperContent AppendFormat( + IFormatProvider provider, + [StringSyntax(StringSyntaxAttribute.CompositeFormat)] string format, + params object[] args) { HtmlContentBuilderExtensions.AppendFormat(this, provider, format, args); return this;