From a1efd6bae266332ae2033740b451eaf98629ce5a Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Sat, 31 Jan 2026 19:23:56 +0100 Subject: [PATCH 1/3] Fix some sonarcloud issues --- .../Extensions/JObjectExtensions.cs | 2 +- .../Extensions/JsonDocumentExtensions.cs | 2 +- src/System.Linq.Dynamic.Core/Extensions/ListExtensions.cs | 1 + src/System.Linq.Dynamic.Core/Parser/ExpressionParser.cs | 2 +- .../Parser/SupportedMethods/MethodFinder.cs | 2 +- 5 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/System.Linq.Dynamic.Core.NewtonsoftJson/Extensions/JObjectExtensions.cs b/src/System.Linq.Dynamic.Core.NewtonsoftJson/Extensions/JObjectExtensions.cs index 2f79840b..1a100a1d 100644 --- a/src/System.Linq.Dynamic.Core.NewtonsoftJson/Extensions/JObjectExtensions.cs +++ b/src/System.Linq.Dynamic.Core.NewtonsoftJson/Extensions/JObjectExtensions.cs @@ -11,7 +11,7 @@ namespace System.Linq.Dynamic.Core.NewtonsoftJson.Extensions; /// internal static class JObjectExtensions { - private class JTokenResolvers : Dictionary>; + private sealed class JTokenResolvers : Dictionary>; private static readonly JTokenResolvers Resolvers = new() { diff --git a/src/System.Linq.Dynamic.Core.SystemTextJson/Extensions/JsonDocumentExtensions.cs b/src/System.Linq.Dynamic.Core.SystemTextJson/Extensions/JsonDocumentExtensions.cs index 3437d3c9..af2501f5 100644 --- a/src/System.Linq.Dynamic.Core.SystemTextJson/Extensions/JsonDocumentExtensions.cs +++ b/src/System.Linq.Dynamic.Core.SystemTextJson/Extensions/JsonDocumentExtensions.cs @@ -8,7 +8,7 @@ namespace System.Linq.Dynamic.Core.SystemTextJson.Extensions; internal static class JsonDocumentExtensions { - private class JTokenResolvers : Dictionary>; + private sealed class JTokenResolvers : Dictionary>; private static readonly JTokenResolvers Resolvers = new() { diff --git a/src/System.Linq.Dynamic.Core/Extensions/ListExtensions.cs b/src/System.Linq.Dynamic.Core/Extensions/ListExtensions.cs index 8885fc4e..7cb20bbc 100644 --- a/src/System.Linq.Dynamic.Core/Extensions/ListExtensions.cs +++ b/src/System.Linq.Dynamic.Core/Extensions/ListExtensions.cs @@ -5,6 +5,7 @@ namespace System.Linq.Dynamic.Core.Extensions; internal static class ListExtensions { internal static void AddIfNotNull(this IList list, T? value) + where T : class { if (value != null) { diff --git a/src/System.Linq.Dynamic.Core/Parser/ExpressionParser.cs b/src/System.Linq.Dynamic.Core/Parser/ExpressionParser.cs index b8091f55..9c5107d4 100644 --- a/src/System.Linq.Dynamic.Core/Parser/ExpressionParser.cs +++ b/src/System.Linq.Dynamic.Core/Parser/ExpressionParser.cs @@ -1980,7 +1980,7 @@ private bool TryFindPropertyOrField(Type type, string id, Expression? expression switch (member) { case PropertyInfo property: - var propertyIsStatic = property?.GetGetMethod().IsStatic ?? property?.GetSetMethod().IsStatic ?? false; + var propertyIsStatic = property.GetGetMethod()?.IsStatic ?? property.GetSetMethod()?.IsStatic ?? false; propertyOrFieldExpression = propertyIsStatic ? Expression.Property(null, property) : Expression.Property(expression, property); return true; diff --git a/src/System.Linq.Dynamic.Core/Parser/SupportedMethods/MethodFinder.cs b/src/System.Linq.Dynamic.Core/Parser/SupportedMethods/MethodFinder.cs index 30877e29..17214eda 100644 --- a/src/System.Linq.Dynamic.Core/Parser/SupportedMethods/MethodFinder.cs +++ b/src/System.Linq.Dynamic.Core/Parser/SupportedMethods/MethodFinder.cs @@ -10,7 +10,7 @@ internal class MethodFinder { private readonly ParsingConfig _parsingConfig; private readonly IExpressionHelper _expressionHelper; - private readonly IDictionary _cachedMethods; + private readonly Dictionary _cachedMethods; /// /// #794 From f3d3e58c2b07118c3418f6468913e8d640f57f2f Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Sun, 1 Feb 2026 08:00:01 +0100 Subject: [PATCH 2/3] . --- .../NewtonsoftJsonExtensions.cs | 4 ++-- .../Utils/NormalizeUtils.cs | 2 +- src/System.Linq.Dynamic.Core/DynamicClassFactory.cs | 2 +- src/System.Linq.Dynamic.Core/Parser/ExpressionHelper.cs | 2 +- src/System.Linq.Dynamic.Core/Parser/ExpressionParser.cs | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/System.Linq.Dynamic.Core.NewtonsoftJson/NewtonsoftJsonExtensions.cs b/src/System.Linq.Dynamic.Core.NewtonsoftJson/NewtonsoftJsonExtensions.cs index ff580c52..d44b3dbf 100644 --- a/src/System.Linq.Dynamic.Core.NewtonsoftJson/NewtonsoftJsonExtensions.cs +++ b/src/System.Linq.Dynamic.Core.NewtonsoftJson/NewtonsoftJsonExtensions.cs @@ -874,12 +874,12 @@ private static IQueryable ToQueryable(JArray source, NewtonsoftJsonParsingConfig config = config ?? NewtonsoftJsonParsingConfig.Default; config.ConvertObjectToSupportComparison = true; - var normalized = config.Normalize == true ? + var normalized = config.Normalize ? NormalizeUtils.NormalizeArray(source, config.NormalizationNonExistingPropertyValueBehavior) : source; return normalized - .ToDynamicJsonClassArray(config?.DynamicJsonClassOptions) + .ToDynamicJsonClassArray(config.DynamicJsonClassOptions) .AsQueryable(); } #endregion diff --git a/src/System.Linq.Dynamic.Core.SystemTextJson/Utils/NormalizeUtils.cs b/src/System.Linq.Dynamic.Core.SystemTextJson/Utils/NormalizeUtils.cs index 7f6e4abf..e748650d 100644 --- a/src/System.Linq.Dynamic.Core.SystemTextJson/Utils/NormalizeUtils.cs +++ b/src/System.Linq.Dynamic.Core.SystemTextJson/Utils/NormalizeUtils.cs @@ -155,7 +155,7 @@ private static JsonObject CreateEmptyObject(Dictionary sc }; } - private static JsonNode? GetNullValue(JsonValueInfo jType) + private static JsonValue? GetNullValue(JsonValueInfo jType) { return jType.Type switch { diff --git a/src/System.Linq.Dynamic.Core/DynamicClassFactory.cs b/src/System.Linq.Dynamic.Core/DynamicClassFactory.cs index 75264a4e..1b4a1eef 100644 --- a/src/System.Linq.Dynamic.Core/DynamicClassFactory.cs +++ b/src/System.Linq.Dynamic.Core/DynamicClassFactory.cs @@ -462,7 +462,7 @@ private static void EmitEqualityOperators(TypeBuilder typeBuilder, MethodBuilder ILGenerator ilNeq = inequalityOperator.GetILGenerator(); - // return !(left == right); + // Define return !(left == right); ilNeq.Emit(OpCodes.Ldarg_0); ilNeq.Emit(OpCodes.Ldarg_1); ilNeq.Emit(OpCodes.Call, equalityOperator); diff --git a/src/System.Linq.Dynamic.Core/Parser/ExpressionHelper.cs b/src/System.Linq.Dynamic.Core/Parser/ExpressionHelper.cs index 8222d4d7..a9b31876 100644 --- a/src/System.Linq.Dynamic.Core/Parser/ExpressionHelper.cs +++ b/src/System.Linq.Dynamic.Core/Parser/ExpressionHelper.cs @@ -540,7 +540,7 @@ private static Expression GenerateStaticMethodCall(string methodName, Expression right = Expression.Convert(right, parameterTypeRight); } - return Expression.Call(null, methodInfo, [left, right]); + return Expression.Call(null, methodInfo, left, right); } private static bool TryGetStaticMethod(string methodName, Expression left, Expression right, [NotNullWhen(true)] out MethodInfo? methodInfo) diff --git a/src/System.Linq.Dynamic.Core/Parser/ExpressionParser.cs b/src/System.Linq.Dynamic.Core/Parser/ExpressionParser.cs index 9c5107d4..20524d36 100644 --- a/src/System.Linq.Dynamic.Core/Parser/ExpressionParser.cs +++ b/src/System.Linq.Dynamic.Core/Parser/ExpressionParser.cs @@ -2545,7 +2545,7 @@ private static Exception IncompatibleOperandsError(string opName, Expression lef var bindingFlags = BindingFlags.Public | BindingFlags.DeclaredOnly | extraBindingFlag; foreach (Type t in TypeHelper.GetSelfAndBaseTypes(type)) { - var findMembersType = _parsingConfig?.IsCaseSensitive == true ? Type.FilterName : Type.FilterNameIgnoreCase; + var findMembersType = _parsingConfig.IsCaseSensitive ? Type.FilterName : Type.FilterNameIgnoreCase; var members = t.FindMembers(MemberTypes.Property | MemberTypes.Field, bindingFlags, findMembersType, memberName); if (members.Length != 0) @@ -2555,7 +2555,7 @@ private static Exception IncompatibleOperandsError(string opName, Expression lef } return null; #else - var isCaseSensitive = _parsingConfig.IsCaseSensitive == true; + var isCaseSensitive = _parsingConfig.IsCaseSensitive; foreach (Type t in TypeHelper.GetSelfAndBaseTypes(type)) { // Try to find a property with the specified memberName From 02455ba79aaa0488d44187a341d377cd36ee9380 Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Sun, 1 Feb 2026 08:20:24 +0100 Subject: [PATCH 3/3] array --- .../Extensions/JObjectExtensions.cs | 2 +- .../Compatibility/EmptyArray.cs | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 src/System.Linq.Dynamic.Core/Compatibility/EmptyArray.cs diff --git a/src/System.Linq.Dynamic.Core.NewtonsoftJson/Extensions/JObjectExtensions.cs b/src/System.Linq.Dynamic.Core.NewtonsoftJson/Extensions/JObjectExtensions.cs index 1a100a1d..5b1161fa 100644 --- a/src/System.Linq.Dynamic.Core.NewtonsoftJson/Extensions/JObjectExtensions.cs +++ b/src/System.Linq.Dynamic.Core.NewtonsoftJson/Extensions/JObjectExtensions.cs @@ -57,7 +57,7 @@ private sealed class JTokenResolvers : Dictionary.Value : ConvertJTokenArray(src, options); } private static object? ConvertJObject(JToken arg, DynamicJsonClassOptions? options = null) diff --git a/src/System.Linq.Dynamic.Core/Compatibility/EmptyArray.cs b/src/System.Linq.Dynamic.Core/Compatibility/EmptyArray.cs new file mode 100644 index 00000000..4ba83704 --- /dev/null +++ b/src/System.Linq.Dynamic.Core/Compatibility/EmptyArray.cs @@ -0,0 +1,11 @@ +// ReSharper disable once CheckNamespace +namespace System; + +internal static class EmptyArray +{ +#if NET35 || NET40 || NET45 || NET452 + public static readonly T[] Value = []; +#else + public static readonly T[] Value = Array.Empty(); +#endif +} \ No newline at end of file