Skip to content

Commit b1a64ff

Browse files
authored
Fix some sonarcloud issues (#971)
* Fix some sonarcloud issues * . * array
1 parent c0e417c commit b1a64ff

File tree

10 files changed

+24
-12
lines changed

10 files changed

+24
-12
lines changed

src/System.Linq.Dynamic.Core.NewtonsoftJson/Extensions/JObjectExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace System.Linq.Dynamic.Core.NewtonsoftJson.Extensions;
1111
/// </summary>
1212
internal static class JObjectExtensions
1313
{
14-
private class JTokenResolvers : Dictionary<JTokenType, Func<JToken, DynamicJsonClassOptions?, object?>>;
14+
private sealed class JTokenResolvers : Dictionary<JTokenType, Func<JToken, DynamicJsonClassOptions?, object?>>;
1515

1616
private static readonly JTokenResolvers Resolvers = new()
1717
{
@@ -57,7 +57,7 @@ private class JTokenResolvers : Dictionary<JTokenType, Func<JToken, DynamicJsonC
5757

5858
internal static IEnumerable ToDynamicJsonClassArray(this JArray? src, DynamicJsonClassOptions? options = null)
5959
{
60-
return src == null ? new object?[0] : ConvertJTokenArray(src, options);
60+
return src == null ? EmptyArray<object?>.Value : ConvertJTokenArray(src, options);
6161
}
6262

6363
private static object? ConvertJObject(JToken arg, DynamicJsonClassOptions? options = null)

src/System.Linq.Dynamic.Core.NewtonsoftJson/NewtonsoftJsonExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -874,12 +874,12 @@ private static IQueryable ToQueryable(JArray source, NewtonsoftJsonParsingConfig
874874
config = config ?? NewtonsoftJsonParsingConfig.Default;
875875
config.ConvertObjectToSupportComparison = true;
876876

877-
var normalized = config.Normalize == true ?
877+
var normalized = config.Normalize ?
878878
NormalizeUtils.NormalizeArray(source, config.NormalizationNonExistingPropertyValueBehavior) :
879879
source;
880880

881881
return normalized
882-
.ToDynamicJsonClassArray(config?.DynamicJsonClassOptions)
882+
.ToDynamicJsonClassArray(config.DynamicJsonClassOptions)
883883
.AsQueryable();
884884
}
885885
#endregion

src/System.Linq.Dynamic.Core.SystemTextJson/Extensions/JsonDocumentExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace System.Linq.Dynamic.Core.SystemTextJson.Extensions;
88

99
internal static class JsonDocumentExtensions
1010
{
11-
private class JTokenResolvers : Dictionary<JsonValueKind, Func<JsonElement, DynamicJsonClassOptions?, object?>>;
11+
private sealed class JTokenResolvers : Dictionary<JsonValueKind, Func<JsonElement, DynamicJsonClassOptions?, object?>>;
1212

1313
private static readonly JTokenResolvers Resolvers = new()
1414
{

src/System.Linq.Dynamic.Core.SystemTextJson/Utils/NormalizeUtils.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ private static JsonObject CreateEmptyObject(Dictionary<string, JsonValueInfo> sc
155155
};
156156
}
157157

158-
private static JsonNode? GetNullValue(JsonValueInfo jType)
158+
private static JsonValue? GetNullValue(JsonValueInfo jType)
159159
{
160160
return jType.Type switch
161161
{
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// ReSharper disable once CheckNamespace
2+
namespace System;
3+
4+
internal static class EmptyArray<T>
5+
{
6+
#if NET35 || NET40 || NET45 || NET452
7+
public static readonly T[] Value = [];
8+
#else
9+
public static readonly T[] Value = Array.Empty<T>();
10+
#endif
11+
}

src/System.Linq.Dynamic.Core/DynamicClassFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ private static void EmitEqualityOperators(TypeBuilder typeBuilder, MethodBuilder
462462

463463
ILGenerator ilNeq = inequalityOperator.GetILGenerator();
464464

465-
// return !(left == right);
465+
// Define return !(left == right);
466466
ilNeq.Emit(OpCodes.Ldarg_0);
467467
ilNeq.Emit(OpCodes.Ldarg_1);
468468
ilNeq.Emit(OpCodes.Call, equalityOperator);

src/System.Linq.Dynamic.Core/Extensions/ListExtensions.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ namespace System.Linq.Dynamic.Core.Extensions;
55
internal static class ListExtensions
66
{
77
internal static void AddIfNotNull<T>(this IList<T> list, T? value)
8+
where T : class
89
{
910
if (value != null)
1011
{

src/System.Linq.Dynamic.Core/Parser/ExpressionHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ private static Expression GenerateStaticMethodCall(string methodName, Expression
540540
right = Expression.Convert(right, parameterTypeRight);
541541
}
542542

543-
return Expression.Call(null, methodInfo, [left, right]);
543+
return Expression.Call(null, methodInfo, left, right);
544544
}
545545

546546
private static bool TryGetStaticMethod(string methodName, Expression left, Expression right, [NotNullWhen(true)] out MethodInfo? methodInfo)

src/System.Linq.Dynamic.Core/Parser/ExpressionParser.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1980,7 +1980,7 @@ private bool TryFindPropertyOrField(Type type, string id, Expression? expression
19801980
switch (member)
19811981
{
19821982
case PropertyInfo property:
1983-
var propertyIsStatic = property?.GetGetMethod().IsStatic ?? property?.GetSetMethod().IsStatic ?? false;
1983+
var propertyIsStatic = property.GetGetMethod()?.IsStatic ?? property.GetSetMethod()?.IsStatic ?? false;
19841984
propertyOrFieldExpression = propertyIsStatic ? Expression.Property(null, property) : Expression.Property(expression, property);
19851985
return true;
19861986

@@ -2545,7 +2545,7 @@ private static Exception IncompatibleOperandsError(string opName, Expression lef
25452545
var bindingFlags = BindingFlags.Public | BindingFlags.DeclaredOnly | extraBindingFlag;
25462546
foreach (Type t in TypeHelper.GetSelfAndBaseTypes(type))
25472547
{
2548-
var findMembersType = _parsingConfig?.IsCaseSensitive == true ? Type.FilterName : Type.FilterNameIgnoreCase;
2548+
var findMembersType = _parsingConfig.IsCaseSensitive ? Type.FilterName : Type.FilterNameIgnoreCase;
25492549
var members = t.FindMembers(MemberTypes.Property | MemberTypes.Field, bindingFlags, findMembersType, memberName);
25502550

25512551
if (members.Length != 0)
@@ -2555,7 +2555,7 @@ private static Exception IncompatibleOperandsError(string opName, Expression lef
25552555
}
25562556
return null;
25572557
#else
2558-
var isCaseSensitive = _parsingConfig.IsCaseSensitive == true;
2558+
var isCaseSensitive = _parsingConfig.IsCaseSensitive;
25592559
foreach (Type t in TypeHelper.GetSelfAndBaseTypes(type))
25602560
{
25612561
// Try to find a property with the specified memberName

src/System.Linq.Dynamic.Core/Parser/SupportedMethods/MethodFinder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ internal class MethodFinder
1010
{
1111
private readonly ParsingConfig _parsingConfig;
1212
private readonly IExpressionHelper _expressionHelper;
13-
private readonly IDictionary<Type, MethodInfo[]> _cachedMethods;
13+
private readonly Dictionary<Type, MethodInfo[]> _cachedMethods;
1414

1515
/// <summary>
1616
/// #794

0 commit comments

Comments
 (0)