Skip to content

Commit 31f21e8

Browse files
author
Bart Koelman
authored
Coding guidelines tweaks (#965)
1 parent 6e4ba03 commit 31f21e8

File tree

195 files changed

+2115
-1545
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

195 files changed

+2115
-1545
lines changed

Build.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function CheckLastExitCode {
1919

2020
function RunInspectCode {
2121
$outputPath = [System.IO.Path]::Combine([System.IO.Path]::GetTempPath(), 'jetbrains-inspectcode-results.xml')
22-
dotnet jb inspectcode JsonApiDotNetCore.sln --output="$outputPath" --properties:Configuration=Release --severity=WARNING --verbosity=WARN -dsl=GlobalAll -dsl=SolutionPersonal -dsl=ProjectPersonal
22+
dotnet jb inspectcode JsonApiDotNetCore.sln --output="$outputPath" --profile=JsonApiDotNetCore-WarningSeverities.DotSettings --properties:Configuration=Release --severity=WARNING --verbosity=WARN -dsl=GlobalAll -dsl=SolutionPersonal -dsl=ProjectPersonal
2323
CheckLastExitCode
2424

2525
[xml]$xml = Get-Content "$outputPath"

CSharpGuidelinesAnalyzer.config

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<cSharpGuidelinesAnalyzerSettings>
3+
<setting rule="AV1561" name="MaxParameterCount" value="6" />
4+
<setting rule="AV1561" name="MaxConstructorParameterCount" value="12" />
5+
</cSharpGuidelinesAnalyzerSettings>

CodingGuidelines.ruleset

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<RuleSet Name="Coding Guidelines" Description=" " ToolsVersion="16.0">
3+
<Rules AnalyzerId="CSharpGuidelinesAnalyzer" RuleNamespace="CSharpGuidelinesAnalyzer">
4+
<Rule Id="AV1500" Action="None" />
5+
<Rule Id="AV1505" Action="Warning" />
6+
<Rule Id="AV1506" Action="Warning" />
7+
<Rule Id="AV1507" Action="Warning" />
8+
<Rule Id="AV1008" Action="Warning" />
9+
<Rule Id="AV1130" Action="Warning" />
10+
<Rule Id="AV1135" Action="Info" />
11+
<Rule Id="AV1536" Action="None" />
12+
<Rule Id="AV1537" Action="None" />
13+
<Rule Id="AV1551" Action="Info" />
14+
<Rule Id="AV1555" Action="Warning" />
15+
<Rule Id="AV1564" Action="Info" />
16+
<Rule Id="AV1568" Action="Warning" />
17+
<Rule Id="AV1706" Action="Warning" />
18+
<Rule Id="AV1710" Action="Info" />
19+
<Rule Id="AV1711" Action="Info" />
20+
<Rule Id="AV1738" Action="Warning" />
21+
<Rule Id="AV1739" Action="Warning" />
22+
<Rule Id="AV1745" Action="Warning" />
23+
<Rule Id="AV1755" Action="Warning" />
24+
<Rule Id="AV2210" Action="None" />
25+
<Rule Id="AV2220" Action="Warning" />
26+
<Rule Id="AV2230" Action="Info" />
27+
<Rule Id="AV2305" Action="None" />
28+
<Rule Id="AV2310" Action="Info" />
29+
<Rule Id="AV2318" Action="Info" />
30+
</Rules>
31+
</RuleSet>

Directory.Build.props

+7
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,15 @@
44
<AspNetCoreVersion>3.1.*</AspNetCoreVersion>
55
<EFCoreVersion>3.1.*</EFCoreVersion>
66
<NpgsqlPostgreSQLVersion>3.1.*</NpgsqlPostgreSQLVersion>
7+
<CodeAnalysisRuleSet>$(SolutionDir)CodingGuidelines.ruleset</CodeAnalysisRuleSet>
78
</PropertyGroup>
89

10+
<ItemGroup>
11+
<AdditionalFiles Include="$(SolutionDir)CSharpGuidelinesAnalyzer.config">
12+
<Link>CSharpGuidelinesAnalyzer.config</Link>
13+
</AdditionalFiles>
14+
</ItemGroup>
15+
916
<PropertyGroup Condition="'$(Configuration)'=='Release'">
1017
<NoWarn>$(NoWarn);1591</NoWarn>
1118
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>

JsonApiDotNetCore-WarningSeverities.DotSettings

+254
Large diffs are not rendered by default.

JsonApiDotNetCore.sln.DotSettings

+4-4
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ JsonApiDotNetCore.ArgumentGuard.NotNull($EXPR$, $NAME$);</s:String>
7272
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=SpecifyStringComparison/@EntryIndexedValue">WARNING</s:String>
7373
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=StringEndsWithIsCultureSpecific/@EntryIndexedValue">WARNING</s:String>
7474
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=StringStartsWithIsCultureSpecific/@EntryIndexedValue">WARNING</s:String>
75+
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=SuggestDiscardDeclarationVarStyle/@EntryIndexedValue">WARNING</s:String>
7576
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=TailRecursiveCall/@EntryIndexedValue">SUGGESTION</s:String>
7677
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=TryCastAlwaysSucceeds/@EntryIndexedValue">WARNING</s:String>
7778
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UnnecessaryWhitespace/@EntryIndexedValue">HINT</s:String>
@@ -554,7 +555,6 @@ JsonApiDotNetCore.ArgumentGuard.NotNull($EXPR$, $NAME$);</s:String>
554555
<s:String x:Key="/Default/CodeStyle/CSharpVarKeywordUsage/ForBuiltInTypes/@EntryValue">UseExplicitType</s:String>
555556
<s:String x:Key="/Default/CodeStyle/CSharpVarKeywordUsage/ForOtherTypes/@EntryValue">UseVarWhenEvident</s:String>
556557
<s:String x:Key="/Default/CodeStyle/CSharpVarKeywordUsage/ForSimpleTypes/@EntryValue">UseVarWhenEvident</s:String>
557-
<s:Boolean x:Key="/Default/CodeStyle/CSharpVarKeywordUsage/PreferExplicitDiscardDeclaration/@EntryValue">True</s:Boolean>
558558
<s:Boolean x:Key="/Default/CodeStyle/CSharpVarKeywordUsage/UseRoslynLogicForEvidentTypes/@EntryValue">False</s:Boolean>
559559
<s:Boolean x:Key="/Default/CodeStyle/EditorConfig/EnableClangFormatSupport/@EntryValue">False</s:Boolean>
560560
<s:Boolean x:Key="/Default/CodeStyle/EditorConfig/EnableEditorConfigSupport/@EntryValue">False</s:Boolean>
@@ -590,7 +590,7 @@ JsonApiDotNetCore.ArgumentGuard.NotNull($EXPR$, $NAME$);</s:String>
590590
<s:String x:Key="/Default/PatternsAndTemplates/StructuralSearch/Pattern/=546845333F49494AB6CF8F0477A0F71D/ReplacePattern/@EntryValue">JsonApiDotNetCore.ArgumentGuard.NotNull($argument$, nameof($argument$));&#xD;
591591
$left$ = $right$;</s:String>
592592
<s:String x:Key="/Default/PatternsAndTemplates/StructuralSearch/Pattern/=546845333F49494AB6CF8F0477A0F71D/SearchPattern/@EntryValue">$left$ = $right$ ?? throw new ArgumentNullException(nameof($argument$));</s:String>
593-
<s:String x:Key="/Default/PatternsAndTemplates/StructuralSearch/Pattern/=546845333F49494AB6CF8F0477A0F71D/Severity/@EntryValue">SUGGESTION</s:String>
593+
<s:String x:Key="/Default/PatternsAndTemplates/StructuralSearch/Pattern/=546845333F49494AB6CF8F0477A0F71D/Severity/@EntryValue">WARNING</s:String>
594594
<s:Boolean x:Key="/Default/PatternsAndTemplates/StructuralSearch/Pattern/=67F8FFFFE7DCA24889232D6952BDFD59/@KeyIndexDefined">True</s:Boolean>
595595
<s:String x:Key="/Default/PatternsAndTemplates/StructuralSearch/Pattern/=67F8FFFFE7DCA24889232D6952BDFD59/Comment/@EntryValue">Replace classic argument null check with Guard clause</s:String>
596596
<s:Boolean x:Key="/Default/PatternsAndTemplates/StructuralSearch/Pattern/=67F8FFFFE7DCA24889232D6952BDFD59/CustomPatternPlaceholder/=argument/@KeyIndexDefined">True</s:Boolean>
@@ -604,7 +604,7 @@ $left$ = $right$;</s:String>
604604
<s:String x:Key="/Default/PatternsAndTemplates/StructuralSearch/Pattern/=67F8FFFFE7DCA24889232D6952BDFD59/ReplaceComment/@EntryValue">Replace argument null check with Guard clause</s:String>
605605
<s:String x:Key="/Default/PatternsAndTemplates/StructuralSearch/Pattern/=67F8FFFFE7DCA24889232D6952BDFD59/ReplacePattern/@EntryValue">JsonApiDotNetCore.ArgumentGuard.NotNull($argument$, nameof($argument$));</s:String>
606606
<s:String x:Key="/Default/PatternsAndTemplates/StructuralSearch/Pattern/=67F8FFFFE7DCA24889232D6952BDFD59/SearchPattern/@EntryValue">if ($argument$ == null) throw new ArgumentNullException(nameof($argument$));</s:String>
607-
<s:String x:Key="/Default/PatternsAndTemplates/StructuralSearch/Pattern/=67F8FFFFE7DCA24889232D6952BDFD59/Severity/@EntryValue">SUGGESTION</s:String>
607+
<s:String x:Key="/Default/PatternsAndTemplates/StructuralSearch/Pattern/=67F8FFFFE7DCA24889232D6952BDFD59/Severity/@EntryValue">WARNING</s:String>
608608
<s:Boolean x:Key="/Default/PatternsAndTemplates/StructuralSearch/Pattern/=B3D9EE6B4EC62A4F961EB15F9ADEC2C6/@KeyIndexDefined">True</s:Boolean>
609609
<s:String x:Key="/Default/PatternsAndTemplates/StructuralSearch/Pattern/=B3D9EE6B4EC62A4F961EB15F9ADEC2C6/Comment/@EntryValue">Replace collection null/empty check with extension method</s:String>
610610
<s:Boolean x:Key="/Default/PatternsAndTemplates/StructuralSearch/Pattern/=B3D9EE6B4EC62A4F961EB15F9ADEC2C6/CustomPatternPlaceholder/=collection/@KeyIndexDefined">True</s:Boolean>
@@ -617,7 +617,7 @@ $left$ = $right$;</s:String>
617617
<s:String x:Key="/Default/PatternsAndTemplates/StructuralSearch/Pattern/=B3D9EE6B4EC62A4F961EB15F9ADEC2C6/ReplaceComment/@EntryValue">Replace collection null/empty check with extension method</s:String>
618618
<s:String x:Key="/Default/PatternsAndTemplates/StructuralSearch/Pattern/=B3D9EE6B4EC62A4F961EB15F9ADEC2C6/ReplacePattern/@EntryValue">$collection$.IsNullOrEmpty()</s:String>
619619
<s:String x:Key="/Default/PatternsAndTemplates/StructuralSearch/Pattern/=B3D9EE6B4EC62A4F961EB15F9ADEC2C6/SearchPattern/@EntryValue">$collection$ == null || !$collection$.Any()</s:String>
620-
<s:String x:Key="/Default/PatternsAndTemplates/StructuralSearch/Pattern/=B3D9EE6B4EC62A4F961EB15F9ADEC2C6/Severity/@EntryValue">SUGGESTION</s:String>
620+
<s:String x:Key="/Default/PatternsAndTemplates/StructuralSearch/Pattern/=B3D9EE6B4EC62A4F961EB15F9ADEC2C6/Severity/@EntryValue">WARNING</s:String>
621621
<s:Boolean x:Key="/Default/UserDictionary/Words/=Assignee/@EntryIndexedValue">True</s:Boolean>
622622
<s:Boolean x:Key="/Default/UserDictionary/Words/=Injectables/@EntryIndexedValue">True</s:Boolean>
623623
<s:Boolean x:Key="/Default/UserDictionary/Words/=linebreaks/@EntryIndexedValue">True</s:Boolean>

benchmarks/BenchmarkResourcePublicNames.cs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#pragma warning disable AV1008 // Class should not be static
2+
13
namespace Benchmarks
24
{
35
internal static class BenchmarkResourcePublicNames

benchmarks/DependencyFactory.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33

44
namespace Benchmarks
55
{
6-
internal static class DependencyFactory
6+
internal sealed class DependencyFactory
77
{
8-
public static IResourceGraph CreateResourceGraph(IJsonApiOptions options)
8+
public IResourceGraph CreateResourceGraph(IJsonApiOptions options)
99
{
1010
var builder = new ResourceGraphBuilder(options, NullLoggerFactory.Instance);
1111
builder.Add<BenchmarkResource>(BenchmarkResourcePublicNames.Type);

benchmarks/Query/QueryParserBenchmarks.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ namespace Benchmarks.Query
2020
[MemoryDiagnoser]
2121
public class QueryParserBenchmarks
2222
{
23+
private readonly DependencyFactory _dependencyFactory = new DependencyFactory();
2324
private readonly FakeRequestQueryStringAccessor _queryStringAccessor = new FakeRequestQueryStringAccessor();
2425
private readonly QueryStringReader _queryStringReaderForSort;
2526
private readonly QueryStringReader _queryStringReaderForAll;
@@ -31,7 +32,7 @@ public QueryParserBenchmarks()
3132
EnableLegacyFilterNotation = true
3233
};
3334

34-
IResourceGraph resourceGraph = DependencyFactory.CreateResourceGraph(options);
35+
IResourceGraph resourceGraph = _dependencyFactory.CreateResourceGraph(options);
3536

3637
var request = new JsonApiRequest
3738
{
@@ -107,7 +108,7 @@ public void ComplexQuery()
107108

108109
private void Run(int iterations, Action action)
109110
{
110-
for (int i = 0; i < iterations; i++)
111+
for (int index = 0; index < iterations; index++)
111112
{
112113
action();
113114
}

benchmarks/Serialization/JsonApiDeserializerBenchmarks.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,13 @@ public class JsonApiDeserializerBenchmarks
2929
}
3030
});
3131

32+
private readonly DependencyFactory _dependencyFactory = new DependencyFactory();
3233
private readonly IJsonApiDeserializer _jsonApiDeserializer;
3334

3435
public JsonApiDeserializerBenchmarks()
3536
{
3637
var options = new JsonApiOptions();
37-
IResourceGraph resourceGraph = DependencyFactory.CreateResourceGraph(options);
38+
IResourceGraph resourceGraph = _dependencyFactory.CreateResourceGraph(options);
3839
var targetedFields = new TargetedFields();
3940
var request = new JsonApiRequest();
4041
var resourceFactory = new ResourceFactory(new ServiceContainer());

benchmarks/Serialization/JsonApiSerializerBenchmarks.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@ public class JsonApiSerializerBenchmarks
2121
Name = Guid.NewGuid().ToString()
2222
};
2323

24+
private readonly DependencyFactory _dependencyFactory = new DependencyFactory();
2425
private readonly IJsonApiSerializer _jsonApiSerializer;
2526

2627
public JsonApiSerializerBenchmarks()
2728
{
2829
var options = new JsonApiOptions();
29-
IResourceGraph resourceGraph = DependencyFactory.CreateResourceGraph(options);
30+
IResourceGraph resourceGraph = _dependencyFactory.CreateResourceGraph(options);
3031
IFieldsToSerialize fieldsToSerialize = CreateFieldsToSerialize(resourceGraph);
3132

3233
IMetaBuilder metaBuilder = new Mock<IMetaBuilder>().Object;

inspectcode.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ if ($LASTEXITCODE -ne 0) {
1616

1717
$outputPath = [System.IO.Path]::Combine([System.IO.Path]::GetTempPath(), 'jetbrains-inspectcode-results.xml')
1818
$resultPath = [System.IO.Path]::Combine([System.IO.Path]::GetTempPath(), 'jetbrains-inspectcode-results.html')
19-
dotnet jb inspectcode JsonApiDotNetCore.sln --output="$outputPath" --properties:Configuration=Release --severity=WARNING --verbosity=WARN -dsl=GlobalAll -dsl=SolutionPersonal -dsl=ProjectPersonal
19+
dotnet jb inspectcode JsonApiDotNetCore.sln --output="$outputPath" --profile=JsonApiDotNetCore-WarningSeverities.DotSettings --properties:Configuration=Release --severity=WARNING --verbosity=WARN -dsl=GlobalAll -dsl=SolutionPersonal -dsl=ProjectPersonal
2020

2121
if ($LASTEXITCODE -ne 0) {
2222
throw "Code inspection failed with exit code $LASTEXITCODE"

src/Examples/JsonApiDotNetCoreExample/Data/AppDbContext.cs

+12-12
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ public AppDbContext(DbContextOptions<AppDbContext> options)
2323
protected override void OnModelCreating(ModelBuilder builder)
2424
{
2525
builder.Entity<TodoItem>()
26-
.HasOne(t => t.Assignee)
27-
.WithMany(p => p.AssignedTodoItems);
26+
.HasOne(todoItem => todoItem.Assignee)
27+
.WithMany(person => person.AssignedTodoItems);
2828

2929
builder.Entity<TodoItem>()
30-
.HasOne(t => t.Owner)
31-
.WithMany(p => p.TodoItems);
30+
.HasOne(todoItem => todoItem.Owner)
31+
.WithMany(person => person.TodoItems);
3232

3333
builder.Entity<ArticleTag>()
3434
.HasKey(bc => new
@@ -45,23 +45,23 @@ protected override void OnModelCreating(ModelBuilder builder)
4545
});
4646

4747
builder.Entity<Person>()
48-
.HasOne(t => t.StakeHolderTodoItem)
49-
.WithMany(t => t.StakeHolders)
48+
.HasOne(person => person.StakeHolderTodoItem)
49+
.WithMany(todoItem => todoItem.StakeHolders)
5050
.OnDelete(DeleteBehavior.Cascade);
5151

5252
builder.Entity<TodoItem>()
53-
.HasMany(t => t.ChildTodoItems)
54-
.WithOne(t => t.ParentTodo);
53+
.HasMany(todoItem => todoItem.ChildTodoItems)
54+
.WithOne(todoItem => todoItem.ParentTodo);
5555

5656
builder.Entity<Passport>()
57-
.HasOne(p => p.Person)
58-
.WithOne(p => p.Passport)
57+
.HasOne(passport => passport.Person)
58+
.WithOne(person => person.Passport)
5959
.HasForeignKey<Person>("PassportKey")
6060
.OnDelete(DeleteBehavior.SetNull);
6161

6262
builder.Entity<TodoItem>()
63-
.HasOne(p => p.OneToOnePerson)
64-
.WithOne(p => p.OneToOneTodoItem)
63+
.HasOne(todoItem => todoItem.OneToOnePerson)
64+
.WithOne(person => person.OneToOneTodoItem)
6565
.HasForeignKey<TodoItem>("OneToOnePersonKey");
6666
}
6767
}

src/Examples/JsonApiDotNetCoreExample/Definitions/ArticleHooksDefinition.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ public ArticleHooksDefinition(IResourceGraph resourceGraph)
2121

2222
public override IEnumerable<Article> OnReturn(HashSet<Article> resources, ResourcePipeline pipeline)
2323
{
24-
if (pipeline == ResourcePipeline.GetSingle && resources.Any(r => r.Caption == "Classified"))
24+
if (pipeline == ResourcePipeline.GetSingle && resources.Any(article => article.Caption == "Classified"))
2525
{
2626
throw new JsonApiException(new Error(HttpStatusCode.Forbidden)
2727
{
2828
Title = "You are not allowed to see this article."
2929
});
3030
}
3131

32-
return resources.Where(article => article.Caption != "This should not be included");
32+
return resources.Where(article => article.Caption != "This should not be included").ToArray();
3333
}
3434
}
3535
}

src/Examples/JsonApiDotNetCoreExample/Definitions/PassportHooksDefinition.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ public override void BeforeRead(ResourcePipeline pipeline, bool isIncluded = fal
3131

3232
public override void BeforeImplicitUpdateRelationship(IRelationshipsDictionary<Passport> resourcesByRelationship, ResourcePipeline pipeline)
3333
{
34-
resourcesByRelationship.GetByRelationship<Person>().ToList().ForEach(kvp => DisallowLocked(kvp.Value));
34+
resourcesByRelationship.GetByRelationship<Person>().ToList().ForEach(pair => DisallowLocked(pair.Value));
3535
}
3636

3737
public override IEnumerable<Passport> OnReturn(HashSet<Passport> resources, ResourcePipeline pipeline)
3838
{
39-
return resources.Where(passport => !passport.IsLocked);
39+
return resources.Where(passport => !passport.IsLocked).ToArray();
4040
}
4141
}
4242
}

src/Examples/JsonApiDotNetCoreExample/Definitions/PersonHooksDefinition.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public override IEnumerable<string> BeforeUpdateRelationship(HashSet<string> ids
2424

2525
public override void BeforeImplicitUpdateRelationship(IRelationshipsDictionary<Person> resourcesByRelationship, ResourcePipeline pipeline)
2626
{
27-
resourcesByRelationship.GetByRelationship<Passport>().ToList().ForEach(kvp => DisallowLocked(kvp.Value));
27+
resourcesByRelationship.GetByRelationship<Passport>().ToList().ForEach(pair => DisallowLocked(pair.Value));
2828
}
2929
}
3030
}

src/Examples/JsonApiDotNetCoreExample/Definitions/TagHooksDefinition.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public TagHooksDefinition(IResourceGraph resourceGraph)
1818

1919
public override IEnumerable<Tag> OnReturn(HashSet<Tag> resources, ResourcePipeline pipeline)
2020
{
21-
return resources.Where(tag => tag.Name != "This should not be included");
21+
return resources.Where(tag => tag.Name != "This should not be included").ToArray();
2222
}
2323
}
2424
}

src/Examples/JsonApiDotNetCoreExample/Definitions/TodoItemHooksDefinition.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ public override void BeforeRead(ResourcePipeline pipeline, bool isIncluded = fal
3131

3232
public override void BeforeImplicitUpdateRelationship(IRelationshipsDictionary<TodoItem> resourcesByRelationship, ResourcePipeline pipeline)
3333
{
34-
List<TodoItem> todoItems = resourcesByRelationship.GetByRelationship<Person>().SelectMany(kvp => kvp.Value).ToList();
34+
List<TodoItem> todoItems = resourcesByRelationship.GetByRelationship<Person>().SelectMany(pair => pair.Value).ToList();
3535
DisallowLocked(todoItems);
3636
}
3737

3838
public override IEnumerable<TodoItem> OnReturn(HashSet<TodoItem> resources, ResourcePipeline pipeline)
3939
{
40-
return resources.Where(todoItem => todoItem.Description != "This should not be included");
40+
return resources.Where(todoItem => todoItem.Description != "This should not be included").ToArray();
4141
}
4242
}
4343
}

src/JsonApiDotNetCore/ArgumentGuard.cs

+17-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
using System.Linq;
44
using JetBrains.Annotations;
55

6+
#pragma warning disable AV1008 // Class should not be static
7+
68
namespace JsonApiDotNetCore
79
{
810
internal static class ArgumentGuard
@@ -20,13 +22,26 @@ public static void NotNull<T>([CanBeNull] [NoEnumeration] T value, [NotNull] [In
2022

2123
[AssertionMethod]
2224
[ContractAnnotation("value: null => halt")]
23-
public static void NotNullNorEmpty<T>([CanBeNull] IEnumerable<T> value, [NotNull] [InvokerParameterName] string name)
25+
public static void NotNullNorEmpty<T>([CanBeNull] IEnumerable<T> value, [NotNull] [InvokerParameterName] string name,
26+
[CanBeNull] string collectionName = null)
2427
{
2528
NotNull(value, name);
2629

2730
if (!value.Any())
2831
{
29-
throw new ArgumentException("Collection cannot be empty.", name);
32+
throw new ArgumentException($"Must have one or more {collectionName ?? name}.", name);
33+
}
34+
}
35+
36+
[AssertionMethod]
37+
[ContractAnnotation("value: null => halt")]
38+
public static void NotNullNorEmpty([CanBeNull] string value, [NotNull] [InvokerParameterName] string name)
39+
{
40+
NotNull(value, name);
41+
42+
if (value == string.Empty)
43+
{
44+
throw new ArgumentException("String cannot be null or empty.", name);
3045
}
3146
}
3247
}

src/JsonApiDotNetCore/ArrayFactory.cs

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#pragma warning disable AV1008 // Class should not be static
2+
#pragma warning disable AV1130 // Return type in method signature should be a collection interface instead of a concrete type
3+
14
namespace JsonApiDotNetCore
25
{
36
internal static class ArrayFactory

0 commit comments

Comments
 (0)