Skip to content

Add CompositeFormat StringSyntaxAttribute syntaxes #44555

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/Html.Abstractions/src/HtmlContentBuilderExtensions.cs
Original file line number Diff line number Diff line change
@@ -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;

/// <summary>
Expand All @@ -24,7 +26,7 @@ public static class HtmlContentBuilderExtensions
/// <returns>A reference to this instance after the append operation has completed.</returns>
public static IHtmlContentBuilder AppendFormat(
this IHtmlContentBuilder builder,
string format,
[StringSyntax(StringSyntaxAttribute.CompositeFormat)] string format,
params object?[] args)
{
if (builder == null)
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 6 additions & 2 deletions src/Html.Abstractions/src/HtmlFormattableString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -25,7 +26,7 @@ public class HtmlFormattableString : IHtmlContent
/// </summary>
/// <param name="format">A composite format string.</param>
/// <param name="args">An array that contains objects to format.</param>
public HtmlFormattableString(string format, params object?[] args)
public HtmlFormattableString([StringSyntax(StringSyntaxAttribute.CompositeFormat)] string format, params object?[] args)
: this(formatProvider: null, format: format, args: args)
{
}
Expand All @@ -37,7 +38,10 @@ public HtmlFormattableString(string format, params object?[] args)
/// <param name="formatProvider">An object that provides culture-specific formatting information.</param>
/// <param name="format">A composite format string.</param>
/// <param name="args">An array that contains objects to format.</param>
public HtmlFormattableString(IFormatProvider? formatProvider, string format, params object?[] args)
public HtmlFormattableString(
IFormatProvider? formatProvider,
[StringSyntax(StringSyntaxAttribute.CompositeFormat)] string format,
params object?[] args)
{
if (format == null)
{
Expand Down
8 changes: 6 additions & 2 deletions src/Razor/Razor/src/TagHelpers/TagHelperContent.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -92,7 +93,7 @@ public TagHelperContent SetHtmlContent(string encoded)
/// </param>
/// <param name="args">The object array to format.</param>
/// <returns>A reference to this instance after the append operation has completed.</returns>
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;
Expand All @@ -109,7 +110,10 @@ public TagHelperContent AppendFormat(string format, params object[] args)
/// </param>
/// <param name="args">The object array to format.</param>
/// <returns>A reference to this instance after the append operation has completed.</returns>
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;
Expand Down