Skip to content

Commit

Permalink
Fix analyzer errors on latest net9.0 SDK (#15712)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastienros authored Apr 10, 2024
1 parent 7296191 commit 4c29c61
Show file tree
Hide file tree
Showing 30 changed files with 81 additions and 76 deletions.
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("-", "");
}

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
Original file line number Diff line number Diff line change
@@ -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<ConditionOptions>(o =>
Expand All @@ -26,6 +28,28 @@ public static IServiceCollection AddCondition<TCondition, TConditionEvaluator, T
where TCondition : Condition
where TConditionEvaluator : IConditionEvaluator
where TConditionFactory : IConditionFactory
=> services.AddCondition(typeof(TCondition), typeof(TConditionEvaluator), typeof(TConditionFactory));
{
return services.AddCondition(typeof(TCondition), typeof(TConditionEvaluator), typeof(TConditionFactory));
}

public static IServiceCollection AddRuleCondition<TCondition, TConditionEvaluator, TConditionFactory>(this IServiceCollection services)
where TCondition : Condition
where TConditionEvaluator : class, IConditionEvaluator
where TConditionFactory : class, IConditionFactory
{
services.Configure<ConditionOptions>(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<TConditionEvaluator>();

services.AddSingleton<IConditionFactory, TConditionFactory>();

services.AddJsonDerivedTypeInfo<TCondition, Condition>();

return services;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,23 @@ public static class ServiceCollectionExtensions
{
public static IServiceCollection AddRule<TCondition, TEvaluator, TDisplayDriver>(this IServiceCollection services)
where TCondition : Condition, new()
where TEvaluator : IConditionEvaluator
where TEvaluator : class, IConditionEvaluator
where TDisplayDriver : class, IDisplayDriver<Condition>
=> services.AddRuleCondition<TCondition, TEvaluator>()
.AddScoped<IDisplayDriver<Condition>, TDisplayDriver>();
{
return services.AddRuleCondition<TCondition, TEvaluator>()
.AddScoped<IDisplayDriver<Condition>, TDisplayDriver>();
}

public static IServiceCollection AddRuleConditionOperator<TOperator>(this IServiceCollection services)
where TOperator : ConditionOperator
=> services.AddJsonDerivedTypeInfo<TOperator, ConditionOperator>();
{
return services.AddJsonDerivedTypeInfo<TOperator, ConditionOperator>();
}

public static IServiceCollection AddRuleCondition<TCondition, TConditionEvaluator>(this IServiceCollection services)
where TCondition : Condition, new()
=> services.AddCondition(typeof(TCondition), typeof(TConditionEvaluator), typeof(ConditionFactory<TCondition>))
.AddJsonDerivedTypeInfo<TCondition, Condition>();

public static IServiceCollection AddRuleCondition<TCondition, TConditionEvaluator, TConditionFactory>(this IServiceCollection services)
where TCondition : Condition
where TConditionEvaluator : IConditionEvaluator
where TConditionFactory : IConditionFactory
=> services.AddCondition(typeof(TCondition), typeof(TConditionEvaluator), typeof(TConditionFactory))
.AddJsonDerivedTypeInfo<TCondition, Condition>();
where TConditionEvaluator : class, IConditionEvaluator
{
return services.AddRuleCondition<TCondition, TConditionEvaluator, ConditionFactory<TCondition>>();
}
}
Loading

0 comments on commit 4c29c61

Please sign in to comment.