From 8d86700f2be71ecaa6e99b452183e24876e119fa Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Wed, 21 Feb 2024 00:00:59 +0000 Subject: [PATCH] style: format code with dotnet-format This commit fixes the style issues introduced in e0a8bc0 according to the output from dotnet-format. Details: None --- src/Mvc/MvcAutoConfigurator.cs | 32 +- src/Mvc/MvcOptions.cs | 427 +++++++++++---------- src/Mvc/TypeNameAndAssemblyConfigurator.cs | 118 +++--- 3 files changed, 289 insertions(+), 288 deletions(-) diff --git a/src/Mvc/MvcAutoConfigurator.cs b/src/Mvc/MvcAutoConfigurator.cs index 4ed9b9cc..fb901d25 100644 --- a/src/Mvc/MvcAutoConfigurator.cs +++ b/src/Mvc/MvcAutoConfigurator.cs @@ -11,20 +11,20 @@ public class MvcAutoConfigurator(ILogger logger) IConfigureIApplicationBuilder, ILog { - public ILogger? Logger => logger; - private const string Mvc = nameof(Mvc); - private const string JsonSerializer = nameof(JsonSerializer); - public ConfigurationOrder Order => ConfigurationOrder.Late; - - public void Configure(WebApplicationBuilder builder) - { - Logger?.MvcAutoConfiguratorConfigureWebApplicationBuilder(); - builder.AddMvc(Mvc, Logger); - } - - public void Configure(IApplicationBuilder builder) - { - Logger.MvcAutoConfiguratorConfigureIApplicationBuilder(); - builder.UseMvc(Mvc, Logger); - } + public ILogger? Logger => logger; +private const string Mvc = nameof(Mvc); +private const string JsonSerializer = nameof(JsonSerializer); +public ConfigurationOrder Order => ConfigurationOrder.Late; + +public void Configure(WebApplicationBuilder builder) +{ + Logger?.MvcAutoConfiguratorConfigureWebApplicationBuilder(); + builder.AddMvc(Mvc, Logger); +} + +public void Configure(IApplicationBuilder builder) +{ + Logger.MvcAutoConfiguratorConfigureIApplicationBuilder(); + builder.UseMvc(Mvc, Logger); +} } diff --git a/src/Mvc/MvcOptions.cs b/src/Mvc/MvcOptions.cs index bce01f42..22567d26 100644 --- a/src/Mvc/MvcOptions.cs +++ b/src/Mvc/MvcOptions.cs @@ -21,217 +21,218 @@ public MvcOptions() AllowEmptyInputInBodyModelBinding = false, RespectBrowserAcceptHeader = true } - ) { } - - /// if you want to add controllers with views, otherwise - public virtual bool AddControllersWithViews { get; set; } = false; - public virtual bool AddControllersAsServices { get; set; } = false; - - /// if you want to add Razor pages, otherwise - public virtual bool AddRazorPages { get; set; } = false; - - /// if you want to add Razor components, otherwise - public virtual bool AddRazorComponents { get; set; } = false; - - /// if you want to add interactive server components, otherwise - public virtual bool AddInteractiveServerComponents { get; set; } = false; - - /// if you want to add controllers with views, otherwise - /// public virtual bool AddControllersAsServices { get; set; } = false; - - /// if you want to add the Microsoft Identity UI, otherwise - public virtual bool AddMicrosoftIdentityUI { get; set; } = false; - - /// if you want to add JSON serializer otherwise - public virtual bool AddJsonOptions { get; set; } = false; - - /// if you want to add XML serializer formatters, otherwise - public virtual bool AddXmlSerializerFormatters { get; set; } = false; - - /// if you want to add XML data contract serializer formatters, otherwise - public virtual bool AddXmlDataContractSerializerFormatters { get; set; } = false; - - /// if you want to add the DGMJR MVC conventions, otherwise - public virtual bool AddMvcConventions { get; set; } = false; - - /// if you want to add controllers, otherwise - public virtual bool AddControllers { get; set; } = false; - - /// - public virtual bool AllowEmptyInputInBodyModelBinding { get; set; } = - mvc.AllowEmptyInputInBodyModelBinding; - - /// - public virtual bool EnableActionInvokers { get; set; } = mvc.EnableActionInvokers; - - /// - public virtual bool EnableEndpointRouting { get; set; } = mvc.EnableEndpointRouting; - - /// - public virtual bool RespectBrowserAcceptHeader { get; set; } = mvc.RespectBrowserAcceptHeader; - - /// - public virtual bool RequireHttpsPermanent { get; set; } = mvc.RequireHttpsPermanent; - - /// - public virtual bool SuppressAsyncSuffixInActionNames { get; set; } = - mvc.SuppressAsyncSuffixInActionNames; - - /// - public virtual bool SuppressInputFormatterBuffering { get; set; } = - mvc.SuppressInputFormatterBuffering; - - /// - public virtual bool SuppressOutputFormatterBuffering { get; set; } = - mvc.SuppressOutputFormatterBuffering; - - /// - public virtual bool ValidateComplexTypesIfChildValidationFails { get; set; } = - mvc.ValidateComplexTypesIfChildValidationFails; - - /// - public virtual bool SuppressImplicitRequiredAttributeForNonNullableReferenceTypes { get; set; } = - mvc.SuppressImplicitRequiredAttributeForNonNullableReferenceTypes; - - /// - public virtual bool ReturnHttpNotAcceptable { get; set; } = mvc.ReturnHttpNotAcceptable; - - /// if you want to use antiforgery, otherwise - /// !!! Only supported in .NET 8.0+ !!!! Ignored otherwise. - public virtual bool UseAntiforgery { get; set; } = true; - - /// - public virtual IDictionary CacheProfiles { get; set; } = - mvc.CacheProfiles; - - /// - public virtual IList Conventions { get; set; } = mvc.Conventions; - - /// - public virtual FilterCollection Filters { get; set; } = mvc.Filters; - - /// - public virtual FormatterMappings FormatterMappings { get; set; } = mvc.FormatterMappings; - - /// - public virtual FormatterCollection InputFormatters { get; set; } = - mvc.InputFormatters; - - /// - public virtual int MaxModelValidationErrors { get; set; } = mvc.MaxModelValidationErrors; - - /// - public virtual IList ModelBinderProviders { get; set; } = - mvc.ModelBinderProviders; - - /// - public virtual DefaultModelBindingMessageProvider ModelBindingMessageProvider { get; set; } = - mvc.ModelBindingMessageProvider; - - /// - public virtual IList ModelMetadataDetailsProviders { get; set; } = - mvc.ModelMetadataDetailsProviders; - - /// - public virtual IList ModelValidatorProviders { get; set; } = - mvc.ModelValidatorProviders; - - /// - public virtual FormatterCollection OutputFormatters { get; set; } = - mvc.OutputFormatters; - - /// - public virtual IList ValueProviderFactories { get; set; } = - mvc.ValueProviderFactories; - - /// - public virtual int? SslPort { get; set; } = mvc.SslPort; - - /// - public virtual int? MaxValidationDepth { get; set; } = mvc.MaxValidationDepth; - - /// - public virtual int MaxModelBindingCollectionSize { get; set; } = - mvc.MaxModelBindingCollectionSize; - - /// - public virtual int MaxModelBindingRecursionDepth { get; set; } = - mvc.MaxModelBindingRecursionDepth; - - /// - public virtual int MaxIAsyncEnumerableBufferLimit { get; set; } = - mvc.MaxIAsyncEnumerableBufferLimit; - - public static implicit operator MsMvcOptions(MvcOptions options) => - options.CopyTo(new MsMvcOptions()); - - public virtual MsMvcOptions CopyTo(MsMvcOptions mvcOpts) - { - mvcOpts.AllowEmptyInputInBodyModelBinding = AllowEmptyInputInBodyModelBinding; - mvcOpts.EnableActionInvokers = EnableActionInvokers; - mvcOpts.EnableEndpointRouting = EnableEndpointRouting; - mvcOpts.MaxIAsyncEnumerableBufferLimit = MaxIAsyncEnumerableBufferLimit; - mvcOpts.MaxModelBindingCollectionSize = MaxModelBindingCollectionSize; - mvcOpts.MaxModelBindingRecursionDepth = MaxModelBindingRecursionDepth; - mvcOpts.MaxModelValidationErrors = MaxModelValidationErrors; - mvcOpts.MaxValidationDepth = MaxValidationDepth; - mvcOpts.RequireHttpsPermanent = RequireHttpsPermanent; - mvcOpts.RespectBrowserAcceptHeader = RespectBrowserAcceptHeader; - mvcOpts.ReturnHttpNotAcceptable = ReturnHttpNotAcceptable; - mvcOpts.SslPort = SslPort; - mvcOpts.SuppressAsyncSuffixInActionNames = SuppressAsyncSuffixInActionNames; - mvcOpts.SuppressImplicitRequiredAttributeForNonNullableReferenceTypes = - SuppressImplicitRequiredAttributeForNonNullableReferenceTypes; - mvcOpts.SuppressInputFormatterBuffering = SuppressInputFormatterBuffering; - mvcOpts.SuppressOutputFormatterBuffering = SuppressOutputFormatterBuffering; - mvcOpts.ValidateComplexTypesIfChildValidationFails = - ValidateComplexTypesIfChildValidationFails; - - // mvcOpts.CacheProfiles.Clear(); - foreach (var profile in CacheProfiles) - { - mvcOpts.CacheProfiles[profile.Key] = profile.Value; - } - // mvcOpts.Filters.Clear(); - foreach (var v in Filters) - { - mvcOpts.Filters.Add(v); - } - // mvcOpts.InputFormatters.Clear(); - foreach (var v in InputFormatters) - { - mvcOpts.InputFormatters.Add(v); - } - // mvcOpts.OutputFormatters.Clear(); - foreach (var v in OutputFormatters) - { - mvcOpts.OutputFormatters.Add(v); - } - // mvcOpts.Conventions.Clear(); - foreach (var v in Conventions) - { - mvcOpts.Conventions.Add(v); - } - // mvcOpts.ValueProviderFactories.Clear(); - foreach (var v in ValueProviderFactories) - { - mvcOpts.ValueProviderFactories.Add(v); - } - // mvcOpts.ModelBinderProviders.Clear(); - foreach (var v in ModelBinderProviders) - { - mvcOpts.ModelBinderProviders.Add(v); - } - // mvcOpts.ModelMetadataDetailsProviders.Clear(); - foreach (var v in ModelMetadataDetailsProviders) - { - mvcOpts.ModelMetadataDetailsProviders.Add(v); - } - // mvcOpts.ModelValidatorProviders.Clear(); - foreach (var v in ModelValidatorProviders) - { - mvcOpts.ModelValidatorProviders.Add(v); - } - return mvcOpts; - } + ) +{ } + +/// if you want to add controllers with views, otherwise +public virtual bool AddControllersWithViews { get; set; } = false; +public virtual bool AddControllersAsServices { get; set; } = false; + +/// if you want to add Razor pages, otherwise +public virtual bool AddRazorPages { get; set; } = false; + +/// if you want to add Razor components, otherwise +public virtual bool AddRazorComponents { get; set; } = false; + +/// if you want to add interactive server components, otherwise +public virtual bool AddInteractiveServerComponents { get; set; } = false; + +/// if you want to add controllers with views, otherwise +/// public virtual bool AddControllersAsServices { get; set; } = false; + +/// if you want to add the Microsoft Identity UI, otherwise +public virtual bool AddMicrosoftIdentityUI { get; set; } = false; + +/// if you want to add JSON serializer otherwise +public virtual bool AddJsonOptions { get; set; } = false; + +/// if you want to add XML serializer formatters, otherwise +public virtual bool AddXmlSerializerFormatters { get; set; } = false; + +/// if you want to add XML data contract serializer formatters, otherwise +public virtual bool AddXmlDataContractSerializerFormatters { get; set; } = false; + +/// if you want to add the DGMJR MVC conventions, otherwise +public virtual bool AddMvcConventions { get; set; } = false; + +/// if you want to add controllers, otherwise +public virtual bool AddControllers { get; set; } = false; + +/// +public virtual bool AllowEmptyInputInBodyModelBinding { get; set; } = + mvc.AllowEmptyInputInBodyModelBinding; + +/// +public virtual bool EnableActionInvokers { get; set; } = mvc.EnableActionInvokers; + +/// +public virtual bool EnableEndpointRouting { get; set; } = mvc.EnableEndpointRouting; + +/// +public virtual bool RespectBrowserAcceptHeader { get; set; } = mvc.RespectBrowserAcceptHeader; + +/// +public virtual bool RequireHttpsPermanent { get; set; } = mvc.RequireHttpsPermanent; + +/// +public virtual bool SuppressAsyncSuffixInActionNames { get; set; } = + mvc.SuppressAsyncSuffixInActionNames; + +/// +public virtual bool SuppressInputFormatterBuffering { get; set; } = + mvc.SuppressInputFormatterBuffering; + +/// +public virtual bool SuppressOutputFormatterBuffering { get; set; } = + mvc.SuppressOutputFormatterBuffering; + +/// +public virtual bool ValidateComplexTypesIfChildValidationFails { get; set; } = + mvc.ValidateComplexTypesIfChildValidationFails; + +/// +public virtual bool SuppressImplicitRequiredAttributeForNonNullableReferenceTypes { get; set; } = + mvc.SuppressImplicitRequiredAttributeForNonNullableReferenceTypes; + +/// +public virtual bool ReturnHttpNotAcceptable { get; set; } = mvc.ReturnHttpNotAcceptable; + +/// if you want to use antiforgery, otherwise +/// !!! Only supported in .NET 8.0+ !!!! Ignored otherwise. +public virtual bool UseAntiforgery { get; set; } = true; + +/// +public virtual IDictionary CacheProfiles { get; set; } = + mvc.CacheProfiles; + +/// +public virtual IList Conventions { get; set; } = mvc.Conventions; + +/// +public virtual FilterCollection Filters { get; set; } = mvc.Filters; + +/// +public virtual FormatterMappings FormatterMappings { get; set; } = mvc.FormatterMappings; + +/// +public virtual FormatterCollection InputFormatters { get; set; } = + mvc.InputFormatters; + +/// +public virtual int MaxModelValidationErrors { get; set; } = mvc.MaxModelValidationErrors; + +/// +public virtual IList ModelBinderProviders { get; set; } = + mvc.ModelBinderProviders; + +/// +public virtual DefaultModelBindingMessageProvider ModelBindingMessageProvider { get; set; } = + mvc.ModelBindingMessageProvider; + +/// +public virtual IList ModelMetadataDetailsProviders { get; set; } = + mvc.ModelMetadataDetailsProviders; + +/// +public virtual IList ModelValidatorProviders { get; set; } = + mvc.ModelValidatorProviders; + +/// +public virtual FormatterCollection OutputFormatters { get; set; } = + mvc.OutputFormatters; + +/// +public virtual IList ValueProviderFactories { get; set; } = + mvc.ValueProviderFactories; + +/// +public virtual int? SslPort { get; set; } = mvc.SslPort; + +/// +public virtual int? MaxValidationDepth { get; set; } = mvc.MaxValidationDepth; + +/// +public virtual int MaxModelBindingCollectionSize { get; set; } = + mvc.MaxModelBindingCollectionSize; + +/// +public virtual int MaxModelBindingRecursionDepth { get; set; } = + mvc.MaxModelBindingRecursionDepth; + +/// +public virtual int MaxIAsyncEnumerableBufferLimit { get; set; } = + mvc.MaxIAsyncEnumerableBufferLimit; + +public static implicit operator MsMvcOptions(MvcOptions options) => + options.CopyTo(new MsMvcOptions()); + +public virtual MsMvcOptions CopyTo(MsMvcOptions mvcOpts) +{ + mvcOpts.AllowEmptyInputInBodyModelBinding = AllowEmptyInputInBodyModelBinding; + mvcOpts.EnableActionInvokers = EnableActionInvokers; + mvcOpts.EnableEndpointRouting = EnableEndpointRouting; + mvcOpts.MaxIAsyncEnumerableBufferLimit = MaxIAsyncEnumerableBufferLimit; + mvcOpts.MaxModelBindingCollectionSize = MaxModelBindingCollectionSize; + mvcOpts.MaxModelBindingRecursionDepth = MaxModelBindingRecursionDepth; + mvcOpts.MaxModelValidationErrors = MaxModelValidationErrors; + mvcOpts.MaxValidationDepth = MaxValidationDepth; + mvcOpts.RequireHttpsPermanent = RequireHttpsPermanent; + mvcOpts.RespectBrowserAcceptHeader = RespectBrowserAcceptHeader; + mvcOpts.ReturnHttpNotAcceptable = ReturnHttpNotAcceptable; + mvcOpts.SslPort = SslPort; + mvcOpts.SuppressAsyncSuffixInActionNames = SuppressAsyncSuffixInActionNames; + mvcOpts.SuppressImplicitRequiredAttributeForNonNullableReferenceTypes = + SuppressImplicitRequiredAttributeForNonNullableReferenceTypes; + mvcOpts.SuppressInputFormatterBuffering = SuppressInputFormatterBuffering; + mvcOpts.SuppressOutputFormatterBuffering = SuppressOutputFormatterBuffering; + mvcOpts.ValidateComplexTypesIfChildValidationFails = + ValidateComplexTypesIfChildValidationFails; + + // mvcOpts.CacheProfiles.Clear(); + foreach (var profile in CacheProfiles) + { + mvcOpts.CacheProfiles[profile.Key] = profile.Value; + } + // mvcOpts.Filters.Clear(); + foreach (var v in Filters) + { + mvcOpts.Filters.Add(v); + } + // mvcOpts.InputFormatters.Clear(); + foreach (var v in InputFormatters) + { + mvcOpts.InputFormatters.Add(v); + } + // mvcOpts.OutputFormatters.Clear(); + foreach (var v in OutputFormatters) + { + mvcOpts.OutputFormatters.Add(v); + } + // mvcOpts.Conventions.Clear(); + foreach (var v in Conventions) + { + mvcOpts.Conventions.Add(v); + } + // mvcOpts.ValueProviderFactories.Clear(); + foreach (var v in ValueProviderFactories) + { + mvcOpts.ValueProviderFactories.Add(v); + } + // mvcOpts.ModelBinderProviders.Clear(); + foreach (var v in ModelBinderProviders) + { + mvcOpts.ModelBinderProviders.Add(v); + } + // mvcOpts.ModelMetadataDetailsProviders.Clear(); + foreach (var v in ModelMetadataDetailsProviders) + { + mvcOpts.ModelMetadataDetailsProviders.Add(v); + } + // mvcOpts.ModelValidatorProviders.Clear(); + foreach (var v in ModelValidatorProviders) + { + mvcOpts.ModelValidatorProviders.Add(v); + } + return mvcOpts; +} } diff --git a/src/Mvc/TypeNameAndAssemblyConfigurator.cs b/src/Mvc/TypeNameAndAssemblyConfigurator.cs index 17ca1787..6adefb70 100644 --- a/src/Mvc/TypeNameAndAssemblyConfigurator.cs +++ b/src/Mvc/TypeNameAndAssemblyConfigurator.cs @@ -14,63 +14,63 @@ public class TypeNameAndAssemblyConfigurator( where U : class { private const string TypeWithAssemblyPattern = - @"^(?([A-Za-z0-9_\.]+(?:\+?[A-Za-z0-9_]+)*(\`\d+\[(?:[^\[\]]+|(\2))*\])?)),\s*(?([A-Za-z0-9_\.]+))$"; - private static readonly Regex TypeWithAssemblyRegex = - new(TypeWithAssemblyPattern, RegexOptions.Compiled); - - public virtual void Configure(T options) - { - var configurationSection = configuration; - if (configurationSectionKey is not null) - { - configurationSection = configuration.GetRequiredSection(configurationSectionKey); - } - - var list = property.Compile().Invoke(options); - - foreach (var t in configurationSection.GetChildren().Select(configSection => configSection.Value).WhereNotNull().Select(type.GetType)) - { - if(t != null) - { - var u = Activator.CreateInstance(t) as U; - if (u is not null) - { - list.Add(u); - } - } - } - } - - // private (string assemblyName, string typeName) GetType(IConfigurationSection section) - // { - // try - // { - // var type = Type.GetType(section.Value); - // if (type is not null) - // return (type.FullName, type.Assembly.GetName().FullName); - // else - // return (section.Value, section.Value); - // } - // catch { } - // return (section.Value, section.Value); - // var match = TypeWithAssemblyRegex.Match(section.Value); - // if (!match.Success) - // { - // throw new InvalidOperationException( - // $"Invalid type name and assembly name configuration: {section.Value}" - // ); - // } - // return (match.Groups["AssemblyName"].Value, match.Groups["TypeName"].Value); - // var parts = section.Value.Split( - // ',', - // StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries - // ); - // var assemblyName = parts[1]; - // var typeName = parts[0]; - // return (assemblyName, typeName); - // var assembly = AssemblyLoadContext.Default.LoadFromAssemblyName( - // new AssemblyName(assemblyName) - // ); - // return assembly.GetType(typeName); - // } + @"^(?([A-Za-z0-9_\.]+(?:\+?[A-Za-z0-9_]+)*(\`\d+\[(?:[^\[\]]+|(\2))*\])?)),\s*(?([A-Za-z0-9_\.]+))$"; +private static readonly Regex TypeWithAssemblyRegex = + new(TypeWithAssemblyPattern, RegexOptions.Compiled); + +public virtual void Configure(T options) +{ + var configurationSection = configuration; + if (configurationSectionKey is not null) + { + configurationSection = configuration.GetRequiredSection(configurationSectionKey); + } + + var list = property.Compile().Invoke(options); + + foreach (var t in configurationSection.GetChildren().Select(configSection => configSection.Value).WhereNotNull().Select(type.GetType)) + { + if (t != null) + { + var u = Activator.CreateInstance(t) as U; + if (u is not null) + { + list.Add(u); + } + } + } +} + +// private (string assemblyName, string typeName) GetType(IConfigurationSection section) +// { +// try +// { +// var type = Type.GetType(section.Value); +// if (type is not null) +// return (type.FullName, type.Assembly.GetName().FullName); +// else +// return (section.Value, section.Value); +// } +// catch { } +// return (section.Value, section.Value); +// var match = TypeWithAssemblyRegex.Match(section.Value); +// if (!match.Success) +// { +// throw new InvalidOperationException( +// $"Invalid type name and assembly name configuration: {section.Value}" +// ); +// } +// return (match.Groups["AssemblyName"].Value, match.Groups["TypeName"].Value); +// var parts = section.Value.Split( +// ',', +// StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries +// ); +// var assemblyName = parts[1]; +// var typeName = parts[0]; +// return (assemblyName, typeName); +// var assembly = AssemblyLoadContext.Default.LoadFromAssemblyName( +// new AssemblyName(assemblyName) +// ); +// return assembly.GetType(typeName); +// } }