Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix analyzer errors on latest net9.0 SDK #15712

Merged
merged 10 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 34 additions & 3 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
sebastienros marked this conversation as resolved.
Show resolved Hide resolved
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
sebastienros marked this conversation as resolved.
Show resolved Hide resolved
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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
3 changes: 2 additions & 1 deletion OrchardCore.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/OrchardCore.Modules/OrchardCore.Admin/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ public override void ConfigureServices(IServiceCollection services)

services.Configure<MvcOptions>((options) =>
{
options.Filters.Add(typeof(AdminFilter));
options.Filters.Add(typeof(AdminMenuFilter));
options.Filters.Add<AdminFilter>();
options.Filters.Add<AdminMenuFilter>();

// Ordered to be called before any global filter.
options.Filters.Add(typeof(AdminZoneFilter), -1000);
options.Filters.Add<AdminZoneFilter>(-1000);
});

services.AddTransient<IAreaControllerRouteMapper, AdminAreaControllerRouteMapper>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public FieldType GetField(ContentPartFieldDefinition field)
Resolver = new FuncFieldResolver<ContentElement, object>(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<ContentPart>(field.PartDefinition.Name);

// Part is not collapsed, access field directly.
contentPart ??= context.Source;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ContentPart>(field.PartDefinition.Name);

// Part is not collapsed, access field directly.
contentPart ??= context.Source;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down
6 changes: 3 additions & 3 deletions src/OrchardCore.Modules/OrchardCore.Demo/GraphQL/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TestQueryObjectType>("lineIgnored"),
new GraphQLField<TestQueryObjectType>("lineOtherIgnored")
});

options
.IgnoreField(typeof(TestQueryObjectType), "lineIgnored")
.IgnoreField<TestQueryObjectType>("lineIgnored");
.IgnoreField<TestQueryObjectType>("lineIgnored")
.IgnoreField<TestQueryObjectType>("lineOtherIgnored");

// Top level Part Options
options.PartOptions = options.PartOptions.Union(new[] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ private EmailMessage FromMailMessage(MailMessage message, Dictionary<string, ILi
{
var data = new byte[attachment.Stream.Length];

attachment.Stream.Read(data, 0, (int)attachment.Stream.Length);
attachment.Stream.ReadExactly(data);

emailMessage.Attachments.Add(new EmailAttachment(attachment.Filename, contentType, new BinaryData(data)));
}
Expand Down
2 changes: 1 addition & 1 deletion src/OrchardCore.Modules/OrchardCore.Facebook/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public override void ConfigureServices(IServiceCollection services)

services.Configure<MvcOptions>((options) =>
{
options.Filters.Add(typeof(FBInitFilter));
options.Filters.Add<FBInitFilter>();
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public override void ConfigureServices(IServiceCollection services)

services.Configure<MvcOptions>((options) =>
{
options.Filters.Add(typeof(FacebookPixelFilter));
options.Filters.Add<FacebookPixelFilter>();
});
}
}
2 changes: 1 addition & 1 deletion src/OrchardCore.Modules/OrchardCore.Layers/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public override void ConfigureServices(IServiceCollection services)

services.Configure<MvcOptions>((options) =>
{
options.Filters.Add(typeof(LayerFilter));
options.Filters.Add<LayerFilter>();
});

services.AddScoped<IDisplayDriver<ISite>, LayerSiteSettingsDisplayDriver>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public override void ConfigureServices(IServiceCollection services)
{
services.Configure<MvcOptions>((options) =>
{
options.Filters.Add(typeof(MiniProfilerFilter));
options.Filters.Add<MiniProfilerFilter>();
});

services.AddScoped<IShapeDisplayEvents, ShapeStep>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,9 @@ public Task<ImmutableArray<ValidationResult>> ValidateSettingsAsync(OpenIdServer
{
var certificates = ImmutableArray.CreateBuilder<(X509Certificate2, StoreLocation, StoreName)>();

foreach (StoreLocation location in Enum.GetValues(typeof(StoreLocation)))
foreach (StoreLocation location in Enum.GetValues<StoreLocation>())
{
foreach (StoreName name in Enum.GetValues(typeof(StoreName)))
foreach (StoreName name in Enum.GetValues<StoreName>())
{
// Note: on non-Windows platforms, an exception can
// be thrown if the store location/name doesn't exist.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
<select asp-for="EncryptionCertificateStoreLocation" class="form-select">
<option value="">@T["None"]</option>

@foreach (StoreLocation location in Enum.GetValues(typeof(StoreLocation)))
@foreach (StoreLocation location in Enum.GetValues<StoreLocation>())
{
<option value="@location" selected="@(Model.EncryptionCertificateStoreLocation == location)">@location.ToString()</option>
}
Expand All @@ -144,7 +144,7 @@
<select asp-for="EncryptionCertificateStoreName" class="form-select">
<option value="">@T["None"]</option>

@foreach (StoreName store in Enum.GetValues(typeof(StoreName)))
@foreach (StoreName store in Enum.GetValues<StoreName>())
{
<option value="@store" selected="@(Model.EncryptionCertificateStoreName == store)">@store.ToString()</option>
}
Expand Down Expand Up @@ -194,7 +194,7 @@
<select asp-for="SigningCertificateStoreLocation" class="form-select">
<option value="">@T["None"]</option>

@foreach (StoreLocation location in Enum.GetValues(typeof(StoreLocation)))
@foreach (StoreLocation location in Enum.GetValues<StoreLocation>())
{
<option value="@location" selected="@(Model.SigningCertificateStoreLocation == location)">@location.ToString()</option>
}
Expand All @@ -208,7 +208,7 @@
<select asp-for="SigningCertificateStoreName" class="form-select">
<option value="">@T["None"]</option>

@foreach (StoreName store in Enum.GetValues(typeof(StoreName)))
@foreach (StoreName store in Enum.GetValues<StoreName>())
{
<option value="@store" selected="@(Model.SigningCertificateStoreName == store)">@store.ToString()</option>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public override void ConfigureServices(IServiceCollection services)
{
services.Configure<MvcOptions>(o =>
{
o.Filters.Add(typeof(WorkflowActionFilter));
o.Filters.Add<WorkflowActionFilter>();
});

services.AddHttpClient();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class XmlRpcWriter : IXmlRpcWriter
/// <summary>
/// Provides the mapping function based on a type.
/// </summary>
private readonly IDictionary<Type, Func<XRpcData, XElement>> _dispatch;
private readonly Dictionary<Type, Func<XRpcData, XElement>> _dispatch;

/// <summary>
/// Initializes a new instance of the <see cref="XmlRpcWriter"/> class.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ namespace OrchardCore.Modules
{
public static class StringExtensions
{
public static string ToHexString(this byte[] bytes)
{
return BitConverter.ToString(bytes).Replace("-", "");
}

Piedone marked this conversation as resolved.
Show resolved Hide resolved
public static byte[] ToByteArray(this string hex)
{
return Enumerable.Range(0, hex.Length).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public static ContentFieldOptionBuilder UseDisplayDriver(this ContentFieldOption
public static ContentFieldOptionBuilder UseDisplayDriver<TContentFieldDisplayDriver>(this ContentFieldOptionBuilder builder, Func<string, bool> predicate)
where TContentFieldDisplayDriver : class, IContentFieldDisplayDriver
{
return builder.ForDisplayMode(typeof(TContentFieldDisplayDriver), predicate)
.ForEditor(typeof(TContentFieldDisplayDriver), predicate);
return builder.ForDisplayMode<TContentFieldDisplayDriver>(predicate)
.ForEditor<TContentFieldDisplayDriver>(predicate);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ private static Action<object, object> 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<object, object>), setterAsAction);
var setterDelegate = setterClosedGenericMethod.CreateDelegate<Action<object, object>>(setterAsAction);

return (Action<object, object>)setterDelegate;
}
Expand All @@ -243,7 +243,7 @@ private static Func<object, object> 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<object, object>), getterAsFunc);
var getterDelegate = getterClosedGenericMethod.CreateDelegate<Func<object, object>>(getterAsFunc);

return (Func<object, object>)getterDelegate;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ public static OrchardCoreBuilder AddTheming(this OrchardCoreBuilder builder)
{
services.Configure<MvcOptions>((options) =>
{
options.Filters.Add(typeof(ModelBinderAccessorFilter));
options.Filters.Add(typeof(NotifyFilter));
options.Filters.Add(typeof(RazorViewActionFilter));
options.Filters.Add<ModelBinderAccessorFilter>();
options.Filters.Add<NotifyFilter>();
options.Filters.Add<RazorViewActionFilter>();
});

services.AddTransient<IConfigureOptions<NotifyJsonSerializerOptions>, NotifyJsonSerializerOptionsConfiguration>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ private async Task InvokeAsync(CommandContext context)
}
}

private static object[] GetInvokeParametersForMethod(MethodInfo methodInfo, IList<string> arguments)
private static object[] GetInvokeParametersForMethod(MethodInfo methodInfo, string[] arguments)
{
var invokeParameters = new List<object>();
var args = new List<string>(arguments);
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/OrchardCore/OrchardCore.Mvc.Core/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<AutoValidateAntiforgeryTokenAttribute>(999);

// Custom model binder to testing purpose
options.ModelBinderProviders.Insert(0, new CheckMarkModelBinderProvider());
Expand Down
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down Expand Up @@ -53,7 +53,7 @@ public static MetaEntry Combine(MetaEntry meta1, MetaEntry meta2, string content
return newMeta;
}

private static void Merge(IDictionary<string, string> d1, params IDictionary<string, string>[] sources)
private static void Merge(AttributeDictionary d1, params AttributeDictionary[] sources)
{
foreach (var d in sources)
{
Expand Down
Loading
Loading