From a8098c5c26837feb49cdbd5abb9db8e21046cea5 Mon Sep 17 00:00:00 2001 From: David Driscoll Date: Thu, 26 Dec 2024 11:10:26 -0500 Subject: [PATCH 1/2] try and fix options detecting the wrong types sometimes --- .editorconfig | 5 +++++ src/Foundation/Conventions/OptionsConvention.cs | 8 +++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/.editorconfig b/.editorconfig index 497bcbbe3..b04c084e4 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1149,6 +1149,9 @@ dotnet_diagnostic.CA1513.severity = none # CA1514: Avoid redundant length argument dotnet_diagnostic.CA1514.severity = none +# CA1515: Consider making public types internal +dotnet_diagnostic.CA1515.severity = none + # CA1700: Do not name enum values 'Reserved' dotnet_diagnostic.CA1700.severity = none # Options: api_surface @@ -3099,6 +3102,8 @@ dotnet_diagnostic.rcs9010.severity = none # Specify ExportCodeFixProviderAttribute.Name dotnet_diagnostic.rcs9011.severity = none +dotnet_diagnostic.RMG012.severity = error # Unmapped target member +dotnet_diagnostic.RMG020.severity = error # Unmapped source member # Refactorings diff --git a/src/Foundation/Conventions/OptionsConvention.cs b/src/Foundation/Conventions/OptionsConvention.cs index 0eed26ad0..d244fef0a 100644 --- a/src/Foundation/Conventions/OptionsConvention.cs +++ b/src/Foundation/Conventions/OptionsConvention.cs @@ -49,18 +49,16 @@ public void Register(IConventionContext context, IConfiguration configuration, I .GetTypes( z => z .NotInfoOf(TypeInfoFilter.Abstract, TypeInfoFilter.Static, TypeInfoFilter.GenericType) - .WithAnyAttribute(typeof(RegisterOptionsConfigurationAttribute)) + .KindOf(TypeKindFilter.Class) + .WithAttribute() ) ); - foreach (var options in classes) + foreach (var (options, attribute) in classes.SelectMany(z => z.GetCustomAttributes(), (type, attribute) => (type, attribute))) { - var attribute = options.GetCustomAttribute()!; - #pragma warning disable IL2060 _configureMethod .MakeGenericMethod(options) .Invoke(null, [services, attribute.OptionsName, configuration.GetSection(attribute.ConfigurationKey)]); - #pragma warning restore IL2060 } } } From f7278a6afc56fbb24c4c9d48609f3949e58ac446 Mon Sep 17 00:00:00 2001 From: Rocket Understudy <33589210+rsg-bot@users.noreply.github.com> Date: Thu, 26 Dec 2024 12:29:12 -0500 Subject: [PATCH 2/2] Automatically linting code --- src/Foundation/Conventions/OptionsConvention.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Foundation/Conventions/OptionsConvention.cs b/src/Foundation/Conventions/OptionsConvention.cs index d244fef0a..2f809acf8 100644 --- a/src/Foundation/Conventions/OptionsConvention.cs +++ b/src/Foundation/Conventions/OptionsConvention.cs @@ -54,9 +54,9 @@ public void Register(IConventionContext context, IConfiguration configuration, I ) ); - foreach (var (options, attribute) in classes.SelectMany(z => z.GetCustomAttributes(), (type, attribute) => (type, attribute))) + foreach (( var options, var attribute ) in classes.SelectMany(z => z.GetCustomAttributes(), (type, attribute) => ( type, attribute ))) { - _configureMethod + _ = _configureMethod .MakeGenericMethod(options) .Invoke(null, [services, attribute.OptionsName, configuration.GetSection(attribute.ConfigurationKey)]); }