diff --git a/src/OrchardCore.Modules/OrchardCore.ContentTypes/ViewModels/EditPartViewModel.cs b/src/OrchardCore.Modules/OrchardCore.ContentTypes/ViewModels/EditPartViewModel.cs index d5e55fac293..e6a00cc628b 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentTypes/ViewModels/EditPartViewModel.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentTypes/ViewModels/EditPartViewModel.cs @@ -2,7 +2,7 @@ using Microsoft.AspNetCore.Mvc.ModelBinding; using OrchardCore.ContentManagement.Metadata.Models; using OrchardCore.ContentManagement.Metadata.Settings; -using OrchardCore.Mvc.Utilities; +using OrchardCore.ContentManagement.Utilities; namespace OrchardCore.ContentTypes.ViewModels; @@ -26,7 +26,7 @@ public EditPartViewModel(ContentPartDefinition contentPartDefinition) [Required] public string DisplayName { - get { return !string.IsNullOrWhiteSpace(_displayName) ? _displayName : Name.TrimEnd("Part").CamelFriendly(); } + get { return !string.IsNullOrWhiteSpace(_displayName) ? _displayName : Name.TrimEndString("Part").CamelFriendly(); } set { _displayName = value; } } diff --git a/src/OrchardCore.Modules/OrchardCore.Demo/Controllers/ContentApiController.cs b/src/OrchardCore.Modules/OrchardCore.Demo/Controllers/ContentApiController.cs index 02c07f60fca..7ec39605e1c 100644 --- a/src/OrchardCore.Modules/OrchardCore.Demo/Controllers/ContentApiController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Demo/Controllers/ContentApiController.cs @@ -55,7 +55,6 @@ public async Task GetAuthorizedById(string id) } [HttpPost] - [Authorize] public async Task AddContent(ContentItem contentItem) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.DemoAPIAccess)) diff --git a/src/OrchardCore.Modules/OrchardCore.Menu/GraphQL/MenuItemContentTypeBuilder.cs b/src/OrchardCore.Modules/OrchardCore.Menu/GraphQL/MenuItemContentTypeBuilder.cs index 6b1b8858d31..f384327ec17 100644 --- a/src/OrchardCore.Modules/OrchardCore.Menu/GraphQL/MenuItemContentTypeBuilder.cs +++ b/src/OrchardCore.Modules/OrchardCore.Menu/GraphQL/MenuItemContentTypeBuilder.cs @@ -1,7 +1,7 @@ +using System; using GraphQL.Resolvers; using GraphQL.Types; using OrchardCore.ContentManagement; -using OrchardCore.ContentManagement.GraphQL; using OrchardCore.ContentManagement.GraphQL.Queries.Types; using OrchardCore.ContentManagement.Metadata.Models; using OrchardCore.Menu.Models; diff --git a/src/OrchardCore.Modules/OrchardCore.Menu/GraphQL/MenuItemsListQueryObjectType.cs b/src/OrchardCore.Modules/OrchardCore.Menu/GraphQL/MenuItemsListQueryObjectType.cs index 24308cf57ee..15627321436 100644 --- a/src/OrchardCore.Modules/OrchardCore.Menu/GraphQL/MenuItemsListQueryObjectType.cs +++ b/src/OrchardCore.Modules/OrchardCore.Menu/GraphQL/MenuItemsListQueryObjectType.cs @@ -10,7 +10,7 @@ public MenuItemsListQueryObjectType() Name = "MenuItemsListPart"; Field>("menuItems") - .Description("The menu items.") + .Description("The menu items.") .Resolve(context => context.Source.MenuItems); } diff --git a/src/OrchardCore/OrchardCore.Abstractions/Json/Serialization/DateTimeJsonConverter.cs b/src/OrchardCore/OrchardCore.Abstractions/Json/Serialization/DateTimeJsonConverter.cs index bf2415e6979..8d694aef46f 100644 --- a/src/OrchardCore/OrchardCore.Abstractions/Json/Serialization/DateTimeJsonConverter.cs +++ b/src/OrchardCore/OrchardCore.Abstractions/Json/Serialization/DateTimeJsonConverter.cs @@ -18,7 +18,7 @@ public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, Jso if (!reader.TryGetDateTime(out var value)) { - var stringValue = reader.GetString(); + var stringValue = reader.GetString(); if (DateTime.TryParse(stringValue, out value)) { return value; diff --git a/src/OrchardCore/OrchardCore.ContentManagement.Abstractions/Metadata/Settings/ContentPartSettingsExtensions.cs b/src/OrchardCore/OrchardCore.ContentManagement.Abstractions/Metadata/Settings/ContentPartSettingsExtensions.cs index 46bd01e3935..ca0bf7484c8 100644 --- a/src/OrchardCore/OrchardCore.ContentManagement.Abstractions/Metadata/Settings/ContentPartSettingsExtensions.cs +++ b/src/OrchardCore/OrchardCore.ContentManagement.Abstractions/Metadata/Settings/ContentPartSettingsExtensions.cs @@ -1,4 +1,3 @@ -using System; using OrchardCore.ContentManagement.Metadata.Builders; using OrchardCore.ContentManagement.Metadata.Models; using OrchardCore.ContentManagement.Utilities; @@ -58,7 +57,7 @@ public static string DisplayName(this ContentPartDefinition part) if (string.IsNullOrEmpty(displayName)) { - displayName = part.Name.TrimEnd("Part"); + displayName = part.Name.TrimEndString("Part"); } return displayName; diff --git a/src/OrchardCore/OrchardCore.ContentManagement.Abstractions/Utilities/StringExtensions.cs b/src/OrchardCore/OrchardCore.ContentManagement.Abstractions/Utilities/StringExtensions.cs index 2fd37ec8de2..9ba29c21a7b 100644 --- a/src/OrchardCore/OrchardCore.ContentManagement.Abstractions/Utilities/StringExtensions.cs +++ b/src/OrchardCore/OrchardCore.ContentManagement.Abstractions/Utilities/StringExtensions.cs @@ -345,6 +345,8 @@ public static string ReplaceAll(this string original, IDictionary replacements[match.Value]); } +#if NET8_0 + [Obsolete("Don't use 'TrimEnd' as this has a different behavior in .NET 9.0. Use 'OrchardCore.ContentManagement.Utilities.TrimEndString' instead.")] public static string TrimEnd(this string value, string trim = "") { if (value == null) @@ -356,6 +358,19 @@ public static string TrimEnd(this string value, string trim = "") ? value[..^trim.Length] : value; } +#endif + + public static string TrimEndString(this string value, string suffix) + { + if (string.IsNullOrWhiteSpace(value)) + { + return value; + } + + return value.EndsWith(suffix, StringComparison.Ordinal) + ? value[..^suffix.Length] + : value; + } public static string ReplaceLastOccurrence(this string source, string searchedValue, string replacedValue) { diff --git a/src/OrchardCore/OrchardCore.ContentManagement.GraphQL/Extensions/StringExtensions.cs b/src/OrchardCore/OrchardCore.ContentManagement.GraphQL/Extensions/StringExtensions.cs index f9b93aead1d..c226eadf506 100644 --- a/src/OrchardCore/OrchardCore.ContentManagement.GraphQL/Extensions/StringExtensions.cs +++ b/src/OrchardCore/OrchardCore.ContentManagement.GraphQL/Extensions/StringExtensions.cs @@ -1,13 +1,12 @@ -using System; using GraphQL; using OrchardCore.ContentManagement.Utilities; -namespace OrchardCore.ContentManagement.GraphQL; +namespace System; public static class StringExtensions { public static string ToFieldName(this string name) { - return name.TrimEnd("Part").ToCamelCase(); + return name.TrimEndString("Part").ToCamelCase(); } } diff --git a/src/OrchardCore/OrchardCore.ContentManagement.GraphQL/Queries/Types/DynamicContentFieldsIndexAliasProvider.cs b/src/OrchardCore/OrchardCore.ContentManagement.GraphQL/Queries/Types/DynamicContentFieldsIndexAliasProvider.cs index 6f5aaec157e..d6d652d2089 100644 --- a/src/OrchardCore/OrchardCore.ContentManagement.GraphQL/Queries/Types/DynamicContentFieldsIndexAliasProvider.cs +++ b/src/OrchardCore/OrchardCore.ContentManagement.GraphQL/Queries/Types/DynamicContentFieldsIndexAliasProvider.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; diff --git a/src/OrchardCore/OrchardCore.ContentManagement.GraphQL/Queries/Types/DynamicContentTypeBuilder.cs b/src/OrchardCore/OrchardCore.ContentManagement.GraphQL/Queries/Types/DynamicContentTypeBuilder.cs index d076a3683c1..73f85b2e256 100644 --- a/src/OrchardCore/OrchardCore.ContentManagement.GraphQL/Queries/Types/DynamicContentTypeBuilder.cs +++ b/src/OrchardCore/OrchardCore.ContentManagement.GraphQL/Queries/Types/DynamicContentTypeBuilder.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.Linq; using GraphQL.Resolvers; diff --git a/src/OrchardCore/OrchardCore.ContentManagement.GraphQL/Queries/Types/TypedContentTypeBuilder.cs b/src/OrchardCore/OrchardCore.ContentManagement.GraphQL/Queries/Types/TypedContentTypeBuilder.cs index a34af732813..02569f1789a 100644 --- a/src/OrchardCore/OrchardCore.ContentManagement.GraphQL/Queries/Types/TypedContentTypeBuilder.cs +++ b/src/OrchardCore/OrchardCore.ContentManagement.GraphQL/Queries/Types/TypedContentTypeBuilder.cs @@ -1,3 +1,4 @@ +using System; using System.Linq; using GraphQL; using GraphQL.Resolvers; diff --git a/src/OrchardCore/OrchardCore.DisplayManagement.Liquid/Tags/ZoneTag.cs b/src/OrchardCore/OrchardCore.DisplayManagement.Liquid/Tags/ZoneTag.cs index 59de447a452..796c7190bb4 100644 --- a/src/OrchardCore/OrchardCore.DisplayManagement.Liquid/Tags/ZoneTag.cs +++ b/src/OrchardCore/OrchardCore.DisplayManagement.Liquid/Tags/ZoneTag.cs @@ -17,7 +17,7 @@ public class ZoneTag public static async ValueTask WriteToAsync( IReadOnlyList argumentsList, IReadOnlyList statements, - TextWriter _, + TextWriter _, TextEncoder encoder, TemplateContext context) { diff --git a/src/OrchardCore/OrchardCore.Mvc.Core/Utilities/StringExtensions.cs b/src/OrchardCore/OrchardCore.Mvc.Core/Utilities/StringExtensions.cs index 5325d08a63b..647398de87f 100644 --- a/src/OrchardCore/OrchardCore.Mvc.Core/Utilities/StringExtensions.cs +++ b/src/OrchardCore/OrchardCore.Mvc.Core/Utilities/StringExtensions.cs @@ -402,6 +402,8 @@ public static string ReplaceAll(this string original, IDictionary replacements[match.Value]); } +#if NET8_0 + [Obsolete("Don't use 'TrimEnd' as this has a different behavior in .NET 9.0. Use 'OrchardCore.ContentManagement.Utilities.TrimEndString' instead.")] public static string TrimEnd(this string rough, string trim = "") { if (rough == null) @@ -413,6 +415,7 @@ public static string TrimEnd(this string rough, string trim = "") ? rough[..^trim.Length] : rough; } +#endif public static string ReplaceLastOccurrence(this string source, string find, string replace) { diff --git a/src/docs/releases/2.0.0.md b/src/docs/releases/2.0.0.md index 86a243bf77f..3cf714f41ac 100644 --- a/src/docs/releases/2.0.0.md +++ b/src/docs/releases/2.0.0.md @@ -739,3 +739,9 @@ Many type commonly used by modules can be `sealed`, which improves runtime perfo ### Workflow Trimming The Workflows module now has a `Trimming` feature to automatically clean up old workflow instances. See [the corresponding documentation](../reference/modules/Workflows/README.md#trimming) for details. + +### Obsoleting `TrimEnd` + +The methods `public static string TrimEnd(this string value, string trim = "")` from `OrchardCore.Mvc.Utilities` and `OrchardCore.ContentManagement.Utilities` are being obsoleted and replaced by +`OrchardCore.ContentManagement.Utilities.TrimEndString(this string value, string suffix)`. This was done to prepare the code base for the next .NET 9.0 release which has a conflicting method +with a different behavior.