Skip to content

Commit

Permalink
Refactorings in preparation of .NET 9.0 support (#16575)
Browse files Browse the repository at this point in the history
Co-authored-by: Georg von Kries <gvk@creativbox.net>
  • Loading branch information
sebastienros and gvkries authored Aug 16, 2024
1 parent 39ffdff commit 6347ef1
Show file tree
Hide file tree
Showing 14 changed files with 36 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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; }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public async Task<IActionResult> GetAuthorizedById(string id)
}

[HttpPost]
[Authorize]
public async Task<IActionResult> AddContent(ContentItem contentItem)
{
if (!await _authorizationService.AuthorizeAsync(User, Permissions.DemoAPIAccess))
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public MenuItemsListQueryObjectType()
Name = "MenuItemsListPart";

Field<ListGraphType<MenuItemInterface>>("menuItems")
.Description("The menu items.")
.Description("The menu items.")
.Resolve(context => context.Source.MenuItems);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using OrchardCore.ContentManagement.Metadata.Builders;
using OrchardCore.ContentManagement.Metadata.Models;
using OrchardCore.ContentManagement.Utilities;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,8 @@ public static string ReplaceAll(this string original, IDictionary<string, string
return Regex.Replace(original, pattern, match => 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)
Expand All @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using GraphQL.Resolvers;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Linq;
using GraphQL;
using GraphQL.Resolvers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class ZoneTag
public static async ValueTask<Completion> WriteToAsync(
IReadOnlyList<FilterArgument> argumentsList,
IReadOnlyList<Statement> statements,
TextWriter _,
TextWriter _,
TextEncoder encoder,
TemplateContext context)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,8 @@ public static string ReplaceAll(this string original, IDictionary<string, string
return Regex.Replace(original, pattern, match => 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)
Expand All @@ -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)
{
Expand Down
6 changes: 6 additions & 0 deletions src/docs/releases/2.0.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

0 comments on commit 6347ef1

Please sign in to comment.