Skip to content

Commit 77d6a6b

Browse files
Fix false-positive warning on possible multiple enumeration
1 parent 05b1163 commit 77d6a6b

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/JsonApiDotNetCore/Queries/NoSqlQueryLayerComposer.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Collections.Generic;
22
using System.Collections.Immutable;
3+
using System.Diagnostics.CodeAnalysis;
34
using System.Linq;
45
using JetBrains.Annotations;
56
using JsonApiDotNetCore.Configuration;
@@ -8,6 +9,7 @@
89
using JsonApiDotNetCore.Resources;
910
using JsonApiDotNetCore.Resources.Annotations;
1011

12+
#pragma warning disable AV1551 // Method overload should call another overload
1113
#pragma warning disable AV2310 // Code block should not contain inline comment
1214

1315
namespace JsonApiDotNetCore.Queries
@@ -36,6 +38,8 @@ public class NoSqlQueryLayerComposer : QueryLayerComposer, INoSqlQueryLayerCompo
3638
private readonly IEnumerable<IQueryConstraintProvider> _constraintProviders;
3739
private readonly ITargetedFields _targetedFields;
3840

41+
// ReSharper disable PossibleMultipleEnumeration
42+
3943
public NoSqlQueryLayerComposer(
4044
IEnumerable<IQueryConstraintProvider> constraintProviders,
4145
IResourceDefinitionAccessor resourceDefinitionAccessor,
@@ -50,6 +54,8 @@ public NoSqlQueryLayerComposer(
5054
_targetedFields = targetedFields;
5155
}
5256

57+
// ReSharper restore PossibleMultipleEnumeration
58+
5359
/// <inheritdoc />
5460
public FilterExpression? GetPrimaryFilterFromConstraintsForNoSql(ResourceType primaryResourceType)
5561
{

src/JsonApiDotNetCore/Services/NoSqlResourceService.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
using Microsoft.Extensions.Logging;
2121
using SysNotNull = System.Diagnostics.CodeAnalysis.NotNullAttribute;
2222

23+
#pragma warning disable AV1551 // Method overload should call another overload
2324
#pragma warning disable AV2310 // Code block should not contain inline comment
2425
#pragma warning disable AV2318 // Work-tracking TO DO comment should be removed
2526
#pragma warning disable AV2407 // Region should be removed
@@ -642,16 +643,13 @@ private static void AssertRelationshipInJsonApiRequestIsNotNull([SysNotNull] Rel
642643
Type type = resource.GetType();
643644
PropertyInfo? property = type.GetProperty(propertyName);
644645

645-
if (property is null)
646-
{
647-
throw new JsonApiException(new ErrorObject(HttpStatusCode.InternalServerError)
646+
return property is not null
647+
? property.GetValue(resource)?.ToString()
648+
: throw new JsonApiException(new ErrorObject(HttpStatusCode.InternalServerError)
648649
{
649650
Title = "Invalid property.",
650651
Detail = $"The '{type.Name}' type does not have a '{propertyName}' property."
651652
});
652-
}
653-
654-
return property.GetValue(resource)?.ToString();
655653
}
656654

657655
#endregion Implementation

0 commit comments

Comments
 (0)