From e8b7636e54f6844bd2f65fb0ec8d77e0ad7dfa0f Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Tue, 9 Apr 2024 11:45:11 -0700 Subject: [PATCH 01/10] Fix new warnings from net9.0 SDK --- .../Json/Serialization/PathStringJsonConverter.cs | 2 +- .../Modules/Extensions/StringExtensions.cs | 5 ----- .../MetaEntry.cs | 4 ++-- .../Modules/StringExtensionsTests.cs | 14 -------------- 4 files changed, 3 insertions(+), 22 deletions(-) diff --git a/src/OrchardCore/OrchardCore.Abstractions/Json/Serialization/PathStringJsonConverter.cs b/src/OrchardCore/OrchardCore.Abstractions/Json/Serialization/PathStringJsonConverter.cs index e0cde2f1ff3..5d4f9da0ae5 100644 --- a/src/OrchardCore/OrchardCore.Abstractions/Json/Serialization/PathStringJsonConverter.cs +++ b/src/OrchardCore/OrchardCore.Abstractions/Json/Serialization/PathStringJsonConverter.cs @@ -22,5 +22,5 @@ public override PathString Read(ref Utf8JsonReader reader, Type typeToConvert, J } public override void Write(Utf8JsonWriter writer, PathString value, JsonSerializerOptions options) - => JsonSerializer.Serialize(writer, value.ToString(), typeof(string), options); + => JsonSerializer.Serialize(writer, value.ToString(), options); } diff --git a/src/OrchardCore/OrchardCore.Abstractions/Modules/Extensions/StringExtensions.cs b/src/OrchardCore/OrchardCore.Abstractions/Modules/Extensions/StringExtensions.cs index d003cd57928..86088bed6f1 100644 --- a/src/OrchardCore/OrchardCore.Abstractions/Modules/Extensions/StringExtensions.cs +++ b/src/OrchardCore/OrchardCore.Abstractions/Modules/Extensions/StringExtensions.cs @@ -7,11 +7,6 @@ namespace OrchardCore.Modules { public static class StringExtensions { - public static string ToHexString(this byte[] bytes) - { - return BitConverter.ToString(bytes).Replace("-", ""); - } - public static byte[] ToByteArray(this string hex) { return Enumerable.Range(0, hex.Length). diff --git a/src/OrchardCore/OrchardCore.ResourceManagement.Abstractions/MetaEntry.cs b/src/OrchardCore/OrchardCore.ResourceManagement.Abstractions/MetaEntry.cs index 4b2b1937214..eba699650a3 100644 --- a/src/OrchardCore/OrchardCore.ResourceManagement.Abstractions/MetaEntry.cs +++ b/src/OrchardCore/OrchardCore.ResourceManagement.Abstractions/MetaEntry.cs @@ -1,6 +1,6 @@ -using System.Collections.Generic; using Microsoft.AspNetCore.Html; using Microsoft.AspNetCore.Mvc.Rendering; +using Microsoft.AspNetCore.Mvc.ViewFeatures; namespace OrchardCore.ResourceManagement { @@ -53,7 +53,7 @@ public static MetaEntry Combine(MetaEntry meta1, MetaEntry meta2, string content return newMeta; } - private static void Merge(IDictionary d1, params IDictionary[] sources) + private static void Merge(AttributeDictionary d1, params AttributeDictionary[] sources) { foreach (var d in sources) { diff --git a/test/OrchardCore.Abstractions.Tests/Modules/StringExtensionsTests.cs b/test/OrchardCore.Abstractions.Tests/Modules/StringExtensionsTests.cs index e57d27059ea..0e2e76b3185 100644 --- a/test/OrchardCore.Abstractions.Tests/Modules/StringExtensionsTests.cs +++ b/test/OrchardCore.Abstractions.Tests/Modules/StringExtensionsTests.cs @@ -5,20 +5,6 @@ namespace OrchardCore.Modules { public class StringExtensionsTests { - [Theory] - [InlineData(new byte[0], "")] - [InlineData(new byte[] { 10, 20, 30 }, "0A141E")] - public void ToHexString_ReturnsCorrectHexString(byte[] bytes, string expected) - { - // Arrange - - // Act - var result = bytes.ToHexString(); - - // Assert - Assert.Equal(expected, result); - } - [Theory] [InlineData("414243", new byte[] { 0x41, 0x42, 0x43 })] [InlineData("48656C6C6F20576F726C64", new byte[] { 0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x57, 0x6F, 0x72, 0x6C, 0x64 })] From cb34d09208f192d30bab2bb51c69c538faa3a394 Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Tue, 9 Apr 2024 11:50:55 -0700 Subject: [PATCH 02/10] More fixes --- .../OrchardCore.XmlRpc/Services/XmlRpcWriter.cs | 2 +- .../Commands/DefaultCommandHandler.cs | 4 ++-- src/OrchardCore/OrchardCore.Mvc.Core/Startup.cs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.XmlRpc/Services/XmlRpcWriter.cs b/src/OrchardCore.Modules/OrchardCore.XmlRpc/Services/XmlRpcWriter.cs index 913e0227098..9e7c5c85871 100644 --- a/src/OrchardCore.Modules/OrchardCore.XmlRpc/Services/XmlRpcWriter.cs +++ b/src/OrchardCore.Modules/OrchardCore.XmlRpc/Services/XmlRpcWriter.cs @@ -15,7 +15,7 @@ public class XmlRpcWriter : IXmlRpcWriter /// /// Provides the mapping function based on a type. /// - private readonly IDictionary> _dispatch; + private readonly Dictionary> _dispatch; /// /// Initializes a new instance of the class. diff --git a/src/OrchardCore/OrchardCore.Infrastructure.Abstractions/Commands/DefaultCommandHandler.cs b/src/OrchardCore/OrchardCore.Infrastructure.Abstractions/Commands/DefaultCommandHandler.cs index a61af845b51..be0b6b8a127 100644 --- a/src/OrchardCore/OrchardCore.Infrastructure.Abstractions/Commands/DefaultCommandHandler.cs +++ b/src/OrchardCore/OrchardCore.Infrastructure.Abstractions/Commands/DefaultCommandHandler.cs @@ -95,7 +95,7 @@ private async Task InvokeAsync(CommandContext context) } } - private static object[] GetInvokeParametersForMethod(MethodInfo methodInfo, IList arguments) + private static object[] GetInvokeParametersForMethod(MethodInfo methodInfo, string[] arguments) { var invokeParameters = new List(); var args = new List(arguments); @@ -130,7 +130,7 @@ private static object[] GetInvokeParametersForMethod(MethodInfo methodInfo, ILis break; } - if (i < arguments.Count) + if (i < arguments.Length) { var val = ConvertToType(methodParameters[i].ParameterType, arguments[i]); if (val == null) return null; diff --git a/src/OrchardCore/OrchardCore.Mvc.Core/Startup.cs b/src/OrchardCore/OrchardCore.Mvc.Core/Startup.cs index 380a760c0c4..2d94d99e75a 100644 --- a/src/OrchardCore/OrchardCore.Mvc.Core/Startup.cs +++ b/src/OrchardCore/OrchardCore.Mvc.Core/Startup.cs @@ -78,7 +78,7 @@ public override void ConfigureServices(IServiceCollection services) // Forcing AntiForgery Token Validation on by default, it's only in Razor Pages by default // Load this filter after the MediaSizeFilterLimitAttribute, but before the // IgnoreAntiforgeryTokenAttribute. refer : https://github.com/aspnet/AspNetCore/issues/10384 - options.Filters.Add(typeof(AutoValidateAntiforgeryTokenAttribute), 999); + options.Filters.Add(999); // Custom model binder to testing purpose options.ModelBinderProviders.Insert(0, new CheckMarkModelBinderProvider()); From 67bf293f8536b290e3e10d1e25f2fe959a066055 Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Tue, 9 Apr 2024 11:54:58 -0700 Subject: [PATCH 03/10] Filters --- src/OrchardCore.Modules/OrchardCore.Admin/Startup.cs | 6 +++--- src/OrchardCore.Modules/OrchardCore.Facebook/Startup.cs | 2 +- .../OrchardCore.Facebook/StartupPixel.cs | 2 +- src/OrchardCore.Modules/OrchardCore.Layers/Startup.cs | 2 +- src/OrchardCore.Modules/OrchardCore.MiniProfiler/Startup.cs | 2 +- .../OrchardCore.Workflows/Http/Startup.cs | 2 +- .../OrchardCoreBuilderExtensions.cs | 6 +++--- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Admin/Startup.cs b/src/OrchardCore.Modules/OrchardCore.Admin/Startup.cs index c8357e3f5fe..41178b4f5ad 100644 --- a/src/OrchardCore.Modules/OrchardCore.Admin/Startup.cs +++ b/src/OrchardCore.Modules/OrchardCore.Admin/Startup.cs @@ -45,11 +45,11 @@ public override void ConfigureServices(IServiceCollection services) services.Configure((options) => { - options.Filters.Add(typeof(AdminFilter)); - options.Filters.Add(typeof(AdminMenuFilter)); + options.Filters.Add(); + options.Filters.Add(); // Ordered to be called before any global filter. - options.Filters.Add(typeof(AdminZoneFilter), -1000); + options.Filters.Add(-1000); }); services.AddTransient(); diff --git a/src/OrchardCore.Modules/OrchardCore.Facebook/Startup.cs b/src/OrchardCore.Modules/OrchardCore.Facebook/Startup.cs index c3b60367320..1b8906f02ed 100644 --- a/src/OrchardCore.Modules/OrchardCore.Facebook/Startup.cs +++ b/src/OrchardCore.Modules/OrchardCore.Facebook/Startup.cs @@ -40,7 +40,7 @@ public override void ConfigureServices(IServiceCollection services) services.Configure((options) => { - options.Filters.Add(typeof(FBInitFilter)); + options.Filters.Add(); }); } } diff --git a/src/OrchardCore.Modules/OrchardCore.Facebook/StartupPixel.cs b/src/OrchardCore.Modules/OrchardCore.Facebook/StartupPixel.cs index fa7541a203b..fbda92a01bd 100644 --- a/src/OrchardCore.Modules/OrchardCore.Facebook/StartupPixel.cs +++ b/src/OrchardCore.Modules/OrchardCore.Facebook/StartupPixel.cs @@ -21,7 +21,7 @@ public override void ConfigureServices(IServiceCollection services) services.Configure((options) => { - options.Filters.Add(typeof(FacebookPixelFilter)); + options.Filters.Add(); }); } } diff --git a/src/OrchardCore.Modules/OrchardCore.Layers/Startup.cs b/src/OrchardCore.Modules/OrchardCore.Layers/Startup.cs index e70d1b00d3a..1a71cf7ab84 100644 --- a/src/OrchardCore.Modules/OrchardCore.Layers/Startup.cs +++ b/src/OrchardCore.Modules/OrchardCore.Layers/Startup.cs @@ -36,7 +36,7 @@ public override void ConfigureServices(IServiceCollection services) services.Configure((options) => { - options.Filters.Add(typeof(LayerFilter)); + options.Filters.Add(); }); services.AddScoped, LayerSiteSettingsDisplayDriver>(); diff --git a/src/OrchardCore.Modules/OrchardCore.MiniProfiler/Startup.cs b/src/OrchardCore.Modules/OrchardCore.MiniProfiler/Startup.cs index a1b1e935c46..657798f459b 100644 --- a/src/OrchardCore.Modules/OrchardCore.MiniProfiler/Startup.cs +++ b/src/OrchardCore.Modules/OrchardCore.MiniProfiler/Startup.cs @@ -19,7 +19,7 @@ public override void ConfigureServices(IServiceCollection services) { services.Configure((options) => { - options.Filters.Add(typeof(MiniProfilerFilter)); + options.Filters.Add(); }); services.AddScoped(); diff --git a/src/OrchardCore.Modules/OrchardCore.Workflows/Http/Startup.cs b/src/OrchardCore.Modules/OrchardCore.Workflows/Http/Startup.cs index 01055854428..61faefdac22 100644 --- a/src/OrchardCore.Modules/OrchardCore.Workflows/Http/Startup.cs +++ b/src/OrchardCore.Modules/OrchardCore.Workflows/Http/Startup.cs @@ -26,7 +26,7 @@ public override void ConfigureServices(IServiceCollection services) { services.Configure(o => { - o.Filters.Add(typeof(WorkflowActionFilter)); + o.Filters.Add(); }); services.AddHttpClient(); diff --git a/src/OrchardCore/OrchardCore.DisplayManagement/OrchardCoreBuilderExtensions.cs b/src/OrchardCore/OrchardCore.DisplayManagement/OrchardCoreBuilderExtensions.cs index e88a0954ff1..2263e740385 100644 --- a/src/OrchardCore/OrchardCore.DisplayManagement/OrchardCoreBuilderExtensions.cs +++ b/src/OrchardCore/OrchardCore.DisplayManagement/OrchardCoreBuilderExtensions.cs @@ -41,9 +41,9 @@ public static OrchardCoreBuilder AddTheming(this OrchardCoreBuilder builder) { services.Configure((options) => { - options.Filters.Add(typeof(ModelBinderAccessorFilter)); - options.Filters.Add(typeof(NotifyFilter)); - options.Filters.Add(typeof(RazorViewActionFilter)); + options.Filters.Add(); + options.Filters.Add(); + options.Filters.Add(); }); services.AddTransient, NotifyJsonSerializerOptionsConfiguration>(); From 354039fa4a237fecf4ba3b5f3405a0fcceafa551 Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Tue, 9 Apr 2024 11:57:16 -0700 Subject: [PATCH 04/10] Enums --- .../OrchardCore.OpenId/Services/OpenIdServerService.cs | 4 ++-- .../Views/OpenIdServerSettings.Edit.cshtml | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.OpenId/Services/OpenIdServerService.cs b/src/OrchardCore.Modules/OrchardCore.OpenId/Services/OpenIdServerService.cs index 381f4185c9c..f555ff5a902 100644 --- a/src/OrchardCore.Modules/OrchardCore.OpenId/Services/OpenIdServerService.cs +++ b/src/OrchardCore.Modules/OrchardCore.OpenId/Services/OpenIdServerService.cs @@ -239,9 +239,9 @@ public Task> ValidateSettingsAsync(OpenIdServer { var certificates = ImmutableArray.CreateBuilder<(X509Certificate2, StoreLocation, StoreName)>(); - foreach (StoreLocation location in Enum.GetValues(typeof(StoreLocation))) + foreach (StoreLocation location in Enum.GetValues()) { - foreach (StoreName name in Enum.GetValues(typeof(StoreName))) + foreach (StoreName name in Enum.GetValues()) { // Note: on non-Windows platforms, an exception can // be thrown if the store location/name doesn't exist. diff --git a/src/OrchardCore.Modules/OrchardCore.OpenId/Views/OpenIdServerSettings.Edit.cshtml b/src/OrchardCore.Modules/OrchardCore.OpenId/Views/OpenIdServerSettings.Edit.cshtml index 2ce255e389e..26189ff7a7d 100644 --- a/src/OrchardCore.Modules/OrchardCore.OpenId/Views/OpenIdServerSettings.Edit.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.OpenId/Views/OpenIdServerSettings.Edit.cshtml @@ -130,7 +130,7 @@ - @foreach (StoreName store in Enum.GetValues(typeof(StoreName))) + @foreach (StoreName store in Enum.GetValues()) { } @@ -194,7 +194,7 @@ - @foreach (StoreName store in Enum.GetValues(typeof(StoreName))) + @foreach (StoreName store in Enum.GetValues()) { } From dcbc04f3d4bb8bb10bb8137c21b7e5f900f92a5a Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Tue, 9 Apr 2024 15:05:33 -0700 Subject: [PATCH 05/10] More warnings --- .../ValidationRules/RequiresPermissionValidationRule.cs | 2 +- .../Services/AzureEmailProviderBase.cs | 2 +- .../ContentDisplay/ContentFieldServiceCollectionExtensions.cs | 4 ++-- .../TagHelpers/LiquidTagHelperActivator.cs | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Apis.GraphQL/ValidationRules/RequiresPermissionValidationRule.cs b/src/OrchardCore.Modules/OrchardCore.Apis.GraphQL/ValidationRules/RequiresPermissionValidationRule.cs index a0aae7945d8..7940a9a10d6 100644 --- a/src/OrchardCore.Modules/OrchardCore.Apis.GraphQL/ValidationRules/RequiresPermissionValidationRule.cs +++ b/src/OrchardCore.Modules/OrchardCore.Apis.GraphQL/ValidationRules/RequiresPermissionValidationRule.cs @@ -69,7 +69,7 @@ private async Task AuthorizeOperationAsync(ASTNode node, ValidationContext valid } } - private async Task AuthorizeNodePermissionAsync(ASTNode node, IFieldType fieldType, ValidationContext validationContext, GraphQLUserContext userContext) + private async Task AuthorizeNodePermissionAsync(ASTNode node, FieldType fieldType, ValidationContext validationContext, GraphQLUserContext userContext) { var permissions = fieldType?.GetPermissions(); diff --git a/src/OrchardCore.Modules/OrchardCore.Email.Azure/Services/AzureEmailProviderBase.cs b/src/OrchardCore.Modules/OrchardCore.Email.Azure/Services/AzureEmailProviderBase.cs index ea2e2171fb8..39e4329eb99 100644 --- a/src/OrchardCore.Modules/OrchardCore.Email.Azure/Services/AzureEmailProviderBase.cs +++ b/src/OrchardCore.Modules/OrchardCore.Email.Azure/Services/AzureEmailProviderBase.cs @@ -210,7 +210,7 @@ private EmailMessage FromMailMessage(MailMessage message, Dictionary(this ContentFieldOptionBuilder builder, Func predicate) where TContentFieldDisplayDriver : class, IContentFieldDisplayDriver { - return builder.ForDisplayMode(typeof(TContentFieldDisplayDriver), predicate) - .ForEditor(typeof(TContentFieldDisplayDriver), predicate); + return builder.ForDisplayMode(predicate) + .ForEditor(predicate); } /// diff --git a/src/OrchardCore/OrchardCore.DisplayManagement.Liquid/TagHelpers/LiquidTagHelperActivator.cs b/src/OrchardCore/OrchardCore.DisplayManagement.Liquid/TagHelpers/LiquidTagHelperActivator.cs index 8f61d82e1ca..188f21b4534 100644 --- a/src/OrchardCore/OrchardCore.DisplayManagement.Liquid/TagHelpers/LiquidTagHelperActivator.cs +++ b/src/OrchardCore/OrchardCore.DisplayManagement.Liquid/TagHelpers/LiquidTagHelperActivator.cs @@ -243,7 +243,7 @@ private static Func MakeFastPropertyGetter(Type type, PropertyIn // Create a delegate TDeclaringType -> { TDeclaringType.Property = TValue; } var getterAsFunc = prop.GetMethod.CreateDelegate(typeof(Func<,>).MakeGenericType(type, prop.PropertyType)); var getterClosedGenericMethod = _callPropertyGetterOpenGenericMethod.MakeGenericMethod(type, prop.PropertyType); - var getterDelegate = getterClosedGenericMethod.CreateDelegate(typeof(Func), getterAsFunc); + var getterDelegate = getterClosedGenericMethod.CreateDelegate>(getterAsFunc); return (Func)getterDelegate; } From 66c9dc676612dc38ae17245c7f433d9ea0ac42cb Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Tue, 9 Apr 2024 15:18:09 -0700 Subject: [PATCH 06/10] More warnings --- .../GraphQL/Fields/ContentFieldsProvider.cs | 2 +- .../GraphQL/Fields/ObjectGraphTypeFieldProvider.cs | 2 +- .../OrchardCore/Modules/Extensions/ShellPipelineExtensions.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.ContentFields/GraphQL/Fields/ContentFieldsProvider.cs b/src/OrchardCore.Modules/OrchardCore.ContentFields/GraphQL/Fields/ContentFieldsProvider.cs index 00fcf81cc6d..23a4db8b563 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentFields/GraphQL/Fields/ContentFieldsProvider.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentFields/GraphQL/Fields/ContentFieldsProvider.cs @@ -102,7 +102,7 @@ public FieldType GetField(ContentPartFieldDefinition field) Resolver = new FuncFieldResolver(context => { // Check if part has been collapsed by trying to get the parent part. - var contentPart = context.Source.Get(typeof(ContentPart), field.PartDefinition.Name); + ContentElement contentPart = context.Source.Get(field.PartDefinition.Name); // Part is not collapsed, access field directly. contentPart ??= context.Source; diff --git a/src/OrchardCore.Modules/OrchardCore.ContentFields/GraphQL/Fields/ObjectGraphTypeFieldProvider.cs b/src/OrchardCore.Modules/OrchardCore.ContentFields/GraphQL/Fields/ObjectGraphTypeFieldProvider.cs index 7bcc4f00dda..678d36551fc 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentFields/GraphQL/Fields/ObjectGraphTypeFieldProvider.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentFields/GraphQL/Fields/ObjectGraphTypeFieldProvider.cs @@ -41,7 +41,7 @@ public FieldType GetField(ContentPartFieldDefinition field) var typeToResolve = context.FieldDefinition.ResolvedType.GetType().BaseType.GetGenericArguments().First(); // Check if part has been collapsed by trying to get the parent part. - var contentPart = context.Source.Get(typeof(ContentPart), field.PartDefinition.Name); + ContentElement contentPart = context.Source.Get(field.PartDefinition.Name); // Part is not collapsed, access field directly. contentPart ??= context.Source; diff --git a/src/OrchardCore/OrchardCore/Modules/Extensions/ShellPipelineExtensions.cs b/src/OrchardCore/OrchardCore/Modules/Extensions/ShellPipelineExtensions.cs index 234bb5dc7ec..49172ace165 100644 --- a/src/OrchardCore/OrchardCore/Modules/Extensions/ShellPipelineExtensions.cs +++ b/src/OrchardCore/OrchardCore/Modules/Extensions/ShellPipelineExtensions.cs @@ -73,7 +73,7 @@ private static async ValueTask BuildPipelineInternalAsync(this S /// /// Configures the tenant pipeline. /// - private static async ValueTask ConfigurePipelineAsync(IApplicationBuilder builder) + private static async ValueTask ConfigurePipelineAsync(ApplicationBuilder builder) { // 'IStartup' instances are ordered by module dependencies with a 'ConfigureOrder' of 0 by default. // 'OrderBy' performs a stable sort, so the order is preserved among equal 'ConfigureOrder' values. From b7fe17071f5b75181dfcc87c2d682616aae965e5 Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Tue, 9 Apr 2024 16:49:55 -0700 Subject: [PATCH 07/10] More suggestions --- .editorconfig | 37 +++++++++++++++++-- OrchardCore.sln | 3 +- .../OrchardCore.Demo/GraphQL/Startup.cs | 6 +-- .../TagHelpers/LiquidTagHelperActivator.cs | 2 +- .../ServiceCollectionExtensions.cs | 26 ++++++++++++- .../ServiceCollectionExtensions.cs | 25 ++++++------- .../FluidShapeRenderBenchmark.cs | 2 +- .../ShapeProxyBenchmark.cs | 8 ++-- 8 files changed, 82 insertions(+), 27 deletions(-) diff --git a/.editorconfig b/.editorconfig index e591a9cd54c..c6365bc10d5 100644 --- a/.editorconfig +++ b/.editorconfig @@ -5,6 +5,24 @@ end_of_line = crlf charset = utf-8 indent_style = space indent_size = 4 +dotnet_style_operator_placement_when_wrapping = beginning_of_line +tab_width = 2 +dotnet_style_coalesce_expression = true:suggestion +dotnet_style_null_propagation = true:suggestion +dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion +dotnet_style_prefer_auto_properties = true:silent +dotnet_style_object_initializer = true:suggestion +dotnet_style_collection_initializer = true:suggestion +dotnet_style_prefer_simplified_boolean_expressions = true:suggestion +dotnet_style_prefer_conditional_expression_over_assignment = true:silent +dotnet_style_prefer_conditional_expression_over_return = true:silent +dotnet_style_explicit_tuple_names = true:suggestion +dotnet_style_prefer_inferred_tuple_names = true:suggestion +dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion +dotnet_style_prefer_compound_assignment = true:suggestion +dotnet_style_prefer_simplified_interpolation = true:suggestion +dotnet_style_prefer_collection_expression = when_types_loosely_match:suggestion +dotnet_style_namespace_match_folder = true:suggestion [*.{json,yml,csproj,props,targets}] indent_size = 2 @@ -30,8 +48,8 @@ dotnet_diagnostic.IDE0305.severity = none dotnet_sort_system_directives_first = true # Code-block preferences -csharp_prefer_braces = true -csharp_prefer_simple_using_statement = true +csharp_prefer_braces = true:silent +csharp_prefer_simple_using_statement = true:suggestion csharp_style_namespace_declarations = file_scoped:suggestion # Range operator @@ -54,7 +72,7 @@ dotnet_style_predefined_type_for_member_access = true : suggestion csharp_style_pattern_matching_over_is_with_cast_check = true : none csharp_style_pattern_matching_over_as_with_null_check = true : none csharp_style_inlined_variable_declaration = true : none -csharp_style_throw_expression = true : none +csharp_style_throw_expression = true:none csharp_style_conditional_delegate_call = true : none dotnet_style_object_initializer = true : suggestion @@ -293,3 +311,16 @@ dotnet_diagnostic.SA1648.severity = none # Inheritdoc should be used dotnet_diagnostic.SA1649.severity = none # File name should match first type name. dotnet_diagnostic.SA1650.severity = none # Element documentation should be spelled correctly. dotnet_diagnostic.SA1651.severity = none # Do not use placeholder elements. +csharp_indent_labels = one_less_than_current +csharp_using_directive_placement = outside_namespace:silent +csharp_style_prefer_method_group_conversion = true:silent +csharp_style_prefer_top_level_statements = true:silent +csharp_style_prefer_primary_constructors = true:suggestion +csharp_style_expression_bodied_methods = false:silent +csharp_style_expression_bodied_constructors = false:silent +csharp_style_expression_bodied_operators = false:silent +csharp_style_expression_bodied_properties = true:silent +csharp_style_expression_bodied_indexers = true:silent +csharp_style_expression_bodied_accessors = true:silent +csharp_style_expression_bodied_lambdas = true:silent +csharp_style_expression_bodied_local_functions = false:silent diff --git a/OrchardCore.sln b/OrchardCore.sln index 4335d613af5..0cf0422cf87 100644 --- a/OrchardCore.sln +++ b/OrchardCore.sln @@ -252,6 +252,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OrchardCore.Workflows.Abstr EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{68F6113F-2F08-4412-B5E7-41B7164A0C7F}" ProjectSection(SolutionItems) = preProject + .editorconfig = .editorconfig gulpfile.js = gulpfile.js package.json = package.json README.md = README.md @@ -519,7 +520,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OrchardCore.Email.Azure", " EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OrchardCore.Email.Smtp", "src\OrchardCore.Modules\OrchardCore.Email.Smtp\OrchardCore.Email.Smtp.csproj", "{E8A1097D-A65A-4B17-A3A2-F50D79552732}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OrchardCore.Rules.Core", "src\OrchardCore\OrchardCore.Rules.Core\OrchardCore.Rules.Core.csproj", "{4BAA08A2-878C-4B96-86BF-5B3DB2B6C2C7}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OrchardCore.Rules.Core", "src\OrchardCore\OrchardCore.Rules.Core\OrchardCore.Rules.Core.csproj", "{4BAA08A2-878C-4B96-86BF-5B3DB2B6C2C7}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/src/OrchardCore.Modules/OrchardCore.Demo/GraphQL/Startup.cs b/src/OrchardCore.Modules/OrchardCore.Demo/GraphQL/Startup.cs index 449f6c2a746..6cbc5e7ff67 100644 --- a/src/OrchardCore.Modules/OrchardCore.Demo/GraphQL/Startup.cs +++ b/src/OrchardCore.Modules/OrchardCore.Demo/GraphQL/Startup.cs @@ -56,13 +56,13 @@ public override void ConfigureServices(IServiceCollection services) // Ignore Fields on GraphQL Objects options.HiddenFields = options.HiddenFields.Union(new[] { - new GraphQLField(typeof(TestQueryObjectType), "lineIgnored"), + new GraphQLField("lineIgnored"), new GraphQLField("lineOtherIgnored") }); options - .IgnoreField(typeof(TestQueryObjectType), "lineIgnored") - .IgnoreField("lineIgnored"); + .IgnoreField("lineIgnored") + .IgnoreField("lineOtherIgnored"); // Top level Part Options options.PartOptions = options.PartOptions.Union(new[] { diff --git a/src/OrchardCore/OrchardCore.DisplayManagement.Liquid/TagHelpers/LiquidTagHelperActivator.cs b/src/OrchardCore/OrchardCore.DisplayManagement.Liquid/TagHelpers/LiquidTagHelperActivator.cs index 188f21b4534..6d6864edf52 100644 --- a/src/OrchardCore/OrchardCore.DisplayManagement.Liquid/TagHelpers/LiquidTagHelperActivator.cs +++ b/src/OrchardCore/OrchardCore.DisplayManagement.Liquid/TagHelpers/LiquidTagHelperActivator.cs @@ -227,7 +227,7 @@ private static Action MakeFastPropertySetter(Type type, Property // Create a delegate TDeclaringType -> { TDeclaringType.Property = TValue; } var setterAsAction = prop.SetMethod.CreateDelegate(typeof(Action<,>).MakeGenericType(type, prop.PropertyType)); var setterClosedGenericMethod = _callPropertySetterOpenGenericMethod.MakeGenericMethod(type, prop.PropertyType); - var setterDelegate = setterClosedGenericMethod.CreateDelegate(typeof(Action), setterAsAction); + var setterDelegate = setterClosedGenericMethod.CreateDelegate>(setterAsAction); return (Action)setterDelegate; } diff --git a/src/OrchardCore/OrchardCore.Rules.Abstractions/ServiceCollectionExtensions.cs b/src/OrchardCore/OrchardCore.Rules.Abstractions/ServiceCollectionExtensions.cs index 9cd171401ab..b05cd6fbf54 100644 --- a/src/OrchardCore/OrchardCore.Rules.Abstractions/ServiceCollectionExtensions.cs +++ b/src/OrchardCore/OrchardCore.Rules.Abstractions/ServiceCollectionExtensions.cs @@ -1,10 +1,12 @@ using System; +using System.Text.Json.Serialization; using Microsoft.Extensions.DependencyInjection; namespace OrchardCore.Rules { public static class ServiceCollectionExtensions { + [Obsolete("This method is deprecated and will be removed in future releases. Please use the .AddRule() or .AddRuleCondition() extensions found in OrchardCore.Rule.Core instead.")] public static IServiceCollection AddCondition(this IServiceCollection services, Type condition, Type conditionEvaluator, Type conditionFactory) { services.Configure(o => @@ -26,6 +28,28 @@ public static IServiceCollection AddCondition services.AddCondition(typeof(TCondition), typeof(TConditionEvaluator), typeof(TConditionFactory)); + { + return services.AddCondition(typeof(TCondition), typeof(TConditionEvaluator), typeof(TConditionFactory)); + } + + public static IServiceCollection AddRuleCondition(this IServiceCollection services) + where TCondition : Condition + where TConditionEvaluator : class, IConditionEvaluator + where TConditionFactory : class, IConditionFactory + { + services.Configure(o => + { + o.AddCondition(typeof(TCondition), typeof(TConditionEvaluator)); + }); + + // Rules are scoped so that during a request rules like the script rule can build the scripting engine once. + services.AddScoped(); + + services.AddSingleton(); + + services.AddJsonDerivedTypeInfo(); + + return services; + } } } diff --git a/src/OrchardCore/OrchardCore.Rules.Core/ServiceCollectionExtensions.cs b/src/OrchardCore/OrchardCore.Rules.Core/ServiceCollectionExtensions.cs index faddaa40e72..7da6746b116 100644 --- a/src/OrchardCore/OrchardCore.Rules.Core/ServiceCollectionExtensions.cs +++ b/src/OrchardCore/OrchardCore.Rules.Core/ServiceCollectionExtensions.cs @@ -8,24 +8,23 @@ public static class ServiceCollectionExtensions { public static IServiceCollection AddRule(this IServiceCollection services) where TCondition : Condition, new() - where TEvaluator : IConditionEvaluator + where TEvaluator : class, IConditionEvaluator where TDisplayDriver : class, IDisplayDriver - => services.AddRuleCondition() - .AddScoped, TDisplayDriver>(); + { + return services.AddRuleCondition() + .AddScoped, TDisplayDriver>(); + } public static IServiceCollection AddRuleConditionOperator(this IServiceCollection services) where TOperator : ConditionOperator - => services.AddJsonDerivedTypeInfo(); + { + return services.AddJsonDerivedTypeInfo(); + } public static IServiceCollection AddRuleCondition(this IServiceCollection services) where TCondition : Condition, new() - => services.AddCondition(typeof(TCondition), typeof(TConditionEvaluator), typeof(ConditionFactory)) - .AddJsonDerivedTypeInfo(); - - public static IServiceCollection AddRuleCondition(this IServiceCollection services) - where TCondition : Condition - where TConditionEvaluator : IConditionEvaluator - where TConditionFactory : IConditionFactory - => services.AddCondition(typeof(TCondition), typeof(TConditionEvaluator), typeof(TConditionFactory)) - .AddJsonDerivedTypeInfo(); + where TConditionEvaluator : class, IConditionEvaluator + { + return services.AddRuleCondition>(); + } } diff --git a/test/OrchardCore.Benchmarks/FluidShapeRenderBenchmark.cs b/test/OrchardCore.Benchmarks/FluidShapeRenderBenchmark.cs index b5d24290479..330c30e9ef5 100644 --- a/test/OrchardCore.Benchmarks/FluidShapeRenderBenchmark.cs +++ b/test/OrchardCore.Benchmarks/FluidShapeRenderBenchmark.cs @@ -28,7 +28,7 @@ static FluidShapeRenderBenchmark() _serviceProvider = new ServiceCollection() .AddScoped(sp => new DisplayHelper(htmlDisplay, null, null)) - .AddTransient(typeof(ShapeRenderFilter)) + .AddTransient() .BuildServiceProvider(); _liquidFilterDelegateResolver = new LiquidFilterDelegateResolver(); diff --git a/test/OrchardCore.Benchmarks/ShapeProxyBenchmark.cs b/test/OrchardCore.Benchmarks/ShapeProxyBenchmark.cs index 01b0cbc9d88..b2b79e294ba 100644 --- a/test/OrchardCore.Benchmarks/ShapeProxyBenchmark.cs +++ b/test/OrchardCore.Benchmarks/ShapeProxyBenchmark.cs @@ -29,13 +29,13 @@ static ShapeProxyBenchmark() { var options = new ProxyGenerationOptions(); options.AddMixinInstance(new ShapeViewModel()); - _proxyType = _proxyGenerator.CreateClassProxy(typeof(MenuItem), options).GetType(); + _proxyType = _proxyGenerator.CreateClassProxy(options).GetType(); } [Benchmark] public object CreateInstance() { - var shape = (IShape)Activator.CreateInstance(typeof(ContentItemViewModel)); + var shape = Activator.CreateInstance(); return shape; } @@ -44,7 +44,7 @@ public object CreateDynamicProxy() { var options = new ProxyGenerationOptions(); options.AddMixinInstance(new ShapeViewModel()); - return (IShape)_proxyGenerator.CreateClassProxy(typeof(MenuItem), options); + return (IShape)_proxyGenerator.CreateClassProxy(options); } [Benchmark] @@ -58,7 +58,7 @@ public object CreateCachedProxy() var options = new ProxyGenerationOptions(); options.AddMixinInstance(new ShapeViewModel()); - var shape = (IShape)_proxyGenerator.CreateClassProxy(typeof(MenuItem), options); + var shape = (IShape)_proxyGenerator.CreateClassProxy(options); _proxyTypesCache.TryAdd(typeof(MenuItem), shape.GetType()); From 1ea09f86d32254ec68b4dfdeeab4c4c8853f7d13 Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Tue, 9 Apr 2024 16:54:56 -0700 Subject: [PATCH 08/10] Concrete type --- .../AuditTrail/Handlers/AuditTrailContentHandler.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/AuditTrail/Handlers/AuditTrailContentHandler.cs b/src/OrchardCore.Modules/OrchardCore.Contents/AuditTrail/Handlers/AuditTrailContentHandler.cs index 8d325601599..641439157ef 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/AuditTrail/Handlers/AuditTrailContentHandler.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/AuditTrail/Handlers/AuditTrailContentHandler.cs @@ -65,7 +65,7 @@ public override Task RestoringAsync(RestoreContentContext context) public override Task RestoredAsync(RestoreContentContext context) => RecordAuditTrailEventAsync(ContentAuditTrailEventConfiguration.Restored, context.ContentItem); - private async Task RecordAuditTrailEventAsync(string name, IContent content) + private async Task RecordAuditTrailEventAsync(string name, ContentItem content) { if (name != ContentAuditTrailEventConfiguration.Restored && _restoring.Contains(content.ContentItem.ContentItemId)) { From d4b6362ae9fc3fd1e1bb70aa7f35924ef492fa62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Ros?= Date: Wed, 10 Apr 2024 10:57:59 -0700 Subject: [PATCH 09/10] Update .editorconfig MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Zoltán Lehóczky --- .editorconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.editorconfig b/.editorconfig index c6365bc10d5..4cc19224c7e 100644 --- a/.editorconfig +++ b/.editorconfig @@ -5,8 +5,8 @@ end_of_line = crlf charset = utf-8 indent_style = space indent_size = 4 -dotnet_style_operator_placement_when_wrapping = beginning_of_line tab_width = 2 +dotnet_style_operator_placement_when_wrapping = beginning_of_line dotnet_style_coalesce_expression = true:suggestion dotnet_style_null_propagation = true:suggestion dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion From 111e293663893a30ec3364a3a4167b123843171c Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Wed, 10 Apr 2024 14:27:19 -0700 Subject: [PATCH 10/10] Revert editorconfig changes --- .editorconfig | 37 +++---------------------------------- 1 file changed, 3 insertions(+), 34 deletions(-) diff --git a/.editorconfig b/.editorconfig index 4cc19224c7e..e591a9cd54c 100644 --- a/.editorconfig +++ b/.editorconfig @@ -5,24 +5,6 @@ end_of_line = crlf charset = utf-8 indent_style = space indent_size = 4 -tab_width = 2 -dotnet_style_operator_placement_when_wrapping = beginning_of_line -dotnet_style_coalesce_expression = true:suggestion -dotnet_style_null_propagation = true:suggestion -dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion -dotnet_style_prefer_auto_properties = true:silent -dotnet_style_object_initializer = true:suggestion -dotnet_style_collection_initializer = true:suggestion -dotnet_style_prefer_simplified_boolean_expressions = true:suggestion -dotnet_style_prefer_conditional_expression_over_assignment = true:silent -dotnet_style_prefer_conditional_expression_over_return = true:silent -dotnet_style_explicit_tuple_names = true:suggestion -dotnet_style_prefer_inferred_tuple_names = true:suggestion -dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion -dotnet_style_prefer_compound_assignment = true:suggestion -dotnet_style_prefer_simplified_interpolation = true:suggestion -dotnet_style_prefer_collection_expression = when_types_loosely_match:suggestion -dotnet_style_namespace_match_folder = true:suggestion [*.{json,yml,csproj,props,targets}] indent_size = 2 @@ -48,8 +30,8 @@ dotnet_diagnostic.IDE0305.severity = none dotnet_sort_system_directives_first = true # Code-block preferences -csharp_prefer_braces = true:silent -csharp_prefer_simple_using_statement = true:suggestion +csharp_prefer_braces = true +csharp_prefer_simple_using_statement = true csharp_style_namespace_declarations = file_scoped:suggestion # Range operator @@ -72,7 +54,7 @@ dotnet_style_predefined_type_for_member_access = true : suggestion csharp_style_pattern_matching_over_is_with_cast_check = true : none csharp_style_pattern_matching_over_as_with_null_check = true : none csharp_style_inlined_variable_declaration = true : none -csharp_style_throw_expression = true:none +csharp_style_throw_expression = true : none csharp_style_conditional_delegate_call = true : none dotnet_style_object_initializer = true : suggestion @@ -311,16 +293,3 @@ dotnet_diagnostic.SA1648.severity = none # Inheritdoc should be used dotnet_diagnostic.SA1649.severity = none # File name should match first type name. dotnet_diagnostic.SA1650.severity = none # Element documentation should be spelled correctly. dotnet_diagnostic.SA1651.severity = none # Do not use placeholder elements. -csharp_indent_labels = one_less_than_current -csharp_using_directive_placement = outside_namespace:silent -csharp_style_prefer_method_group_conversion = true:silent -csharp_style_prefer_top_level_statements = true:silent -csharp_style_prefer_primary_constructors = true:suggestion -csharp_style_expression_bodied_methods = false:silent -csharp_style_expression_bodied_constructors = false:silent -csharp_style_expression_bodied_operators = false:silent -csharp_style_expression_bodied_properties = true:silent -csharp_style_expression_bodied_indexers = true:silent -csharp_style_expression_bodied_accessors = true:silent -csharp_style_expression_bodied_lambdas = true:silent -csharp_style_expression_bodied_local_functions = false:silent