Skip to content
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

OSOE-606: Fixing new C# 11 analyzer violations #68

Merged
merged 3 commits into from
Jun 6, 2023
Merged
Changes from 1 commit
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
14 changes: 7 additions & 7 deletions Lombiq.BaseTheme/Models/ZoneDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
using Microsoft.AspNetCore.Html;
using OrchardCore.DisplayManagement.Razor;
using OrchardCore.DisplayManagement.Zones;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Threading.Tasks;

Expand Down Expand Up @@ -47,7 +47,7 @@ public async Task<IHtmlContent> DisplayZoneAsync<TModel>(
var id = ZoneName.ToCamelCase();
var layoutClassName = string.IsNullOrEmpty(parent)
? "layout" + ZoneName
: FormattableString.Invariant($"layout{parent}__{id}");
: string.Create(CultureInfo.InvariantCulture, $"layout{parent}__{id}");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be very verbose. Can't we have some shorter helper method in HL?

For example:

public static class StringCreator
{
    public static string Invariant(this DefaultInterpolatedStringHandler value) =>
        string.Create(CultureInfo.InvariantCulture, ref value);
}

Then this line would become:

Suggested change
: string.Create(CultureInfo.InvariantCulture, $"layout{parent}__{id}");
: StringCreator.Invariant($"layout{parent}__{id}");

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or:

Suggested change
: string.Create(CultureInfo.InvariantCulture, $"layout{parent}__{id}");
: InvariantString.New($"layout{parent}__{id}");

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked into this but didn't try DefaultInterpolatedStringHandler (since you can't simply pass around FormattableString, simple approaches won't work), thanks.


var classNames = classHolder.ConcatenateZoneClasses(
ZoneName,
Expand All @@ -69,17 +69,17 @@ public async Task<IHtmlContent> DisplayZoneAsync<TModel>(
var elementName = ZoneName == ZoneNames.Content ? "main" : "div";

body = new HtmlContentBuilder()
.AppendHtml(FormattableString.Invariant($"<{elementName} class=\"{bodyWrapperClass} {LeafClassName}\">"))
.AppendHtml(string.Create(CultureInfo.InvariantCulture, $"<{elementName} class=\"{bodyWrapperClass} {LeafClassName}\">"))
.AppendHtml(body)
.AppendHtml(FormattableString.Invariant($"</{elementName}>"));
.AppendHtml(string.Create(CultureInfo.InvariantCulture, $"</{elementName}>"));
}

return new HtmlContentBuilder()
.AppendHtml(FormattableString.Invariant($"<{ElementName} id=\"{id}\" class=\"{classNames}\">"))
.AppendHtml(string.Create(CultureInfo.InvariantCulture, $"<{ElementName} id=\"{id}\" class=\"{classNames}\">"))
.AppendHtml(await ConcatenateAsync(classHolder, page, ChildrenBefore, parent))
.AppendHtml(body)
.AppendHtml(await ConcatenateAsync(classHolder, page, ChildrenAfter, parent))
.AppendHtml(FormattableString.Invariant($"</{ElementName}>"));
.AppendHtml(string.Create(CultureInfo.InvariantCulture, $"</{ElementName}>"));
}

private Task<IHtmlContent> ConcatenateAsync<TModel>(
Expand All @@ -102,7 +102,7 @@ private static async Task<IHtmlContent> ConcatenateInnerAsync<TModel>(

var newParent = string.IsNullOrEmpty(parent)
? zoneName
: FormattableString.Invariant($"{parent}__{zoneName}");
: string.Create(CultureInfo.InvariantCulture, $"{parent}__{zoneName}");

foreach (var zoneDescriptor in zoneDescriptors)
{
Expand Down