Skip to content

Commit 88f19ae

Browse files
Bart Koelmanmaurei
Bart Koelman
andauthored
Code cleanup (#691)
* Fixed: XML comment is not placed on a valid language element * Fixed: Convert to method group * Fixed: Use null propagation * Fixed: Use string interpolation expression * Fixed: Use lambda expression * Fixed: Convert to compound assignment * Fixed: Convert to 'using' declaration * Fixed: Use 'await using' * Fixed: Convert to '?:' expression * Fixed: Merge conditional expression * Fixed: Use object initializer * Fixed: Qualifier is redundant * Fixed: Using directive is not required by the code and can be safely removed * Fixed: Redundant explicit array type specification * Fixed: Type argument specification is redundant * Fixed: Comparison with true is redundant * Fixed: Redundant string interpolation * Fixed: Conditional access qualifier expression is known to be not null * Fixed: Empty object or collection initializer list is redundant * Fixed: Redundant explicit array creation in argument of 'params' parameter * Fixed: Type cast is redundant * Fixed: The parameter {name} has the same default value * Fixed: Empty argument list is redundant * Fixed: Expression is always null * Fixed: Value assigned is not used in any execution path * Fixed: Redundant 'IEnumerable.Cast<T>' call * Fixed: '??' right operand is always null * Fixed: Redundant 'Object.ToString()' call * Fixed: Qualifier 'base.' is redundant * Fixed: The field is always assigned before being used and can be converted to local variable * Fixed: Merge cast with type check * Fixed: Replace with single call to First(..) * Fixed: Replace 'Enumerable.Count()' invocation with collection count property access * Fixed: Use format specifier * Fixed: Field is assigned but its value is never used * Fixed: Field can be made readonly * Fixed: Redundant method override * Fixed: Method is never used * Fixed: Base interface is redundant * Fixed: Field is never used * Fixed: Local variable is never used * Fixed: Method return value is never used * Fixed: Constructor is never used * Fixed: shared instance is never used * Fixed: Parameter is never used * Fixed: Method is never used * Fixed: Initializing field/property by default value is redundant * Fixed: Redundant base constructor call * Fixed: parameter hides outer local variable with the same name * Fixed: Cannot resolve symbol 'dynamic' * Fixed: Possible unintended reference comparison * Fixed: Co-variant array conversion can cause run-time exception on write operation * Fixed: Return value of pure method is not used * Fixed: Auto-property can be made get-only * Fixed: Inconsistent body style: use expression-bodied property * Fixed: Empty statement is redundant * Fixed: Local variable can be declared in inner scope * Fixed: Join declaration and assignment * Fixed: Convert constructor to protected in abstract class * Fixed: Replace with single call to FirstOrDefault/Count * Fixed: Use single deconstruction declaration * Fixed: Removed unused using directives * Fixed a few obvious naming violations * Fixed: Virtual member that is never overridden * Removed DefaultPageSize/RequestedPageSize from IPageService because where the calculated value comes from is an implementation detail and should not be exposed to external code that uses paging. * Fixed: Initializing property by default value is redundant * Reduced accessibility for some non-public types/members * Fixed: missing checkbox in Solution Configuration Manager * Made non-public (and a few public) types sealed * Fixed: Inconsistent modifiers style * Removed reference to xunit from benchmarks project, so that 'dotnet test' does not try to run tests from it * Empty commit to retry cibuild * Update IQueryableExtensions.cs Co-authored-by: Maurits Moeys <maurei@users.noreply.github.com>
1 parent ec5f8d5 commit 88f19ae

File tree

236 files changed

+1000
-1302
lines changed

Some content is hidden

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

236 files changed

+1000
-1302
lines changed

JsonApiDotnetCore.sln

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ Global
108108
{DF0FCFB2-CB12-44BA-BBB5-1BE0BCFCD14C}.Debug|x86.ActiveCfg = Debug|Any CPU
109109
{DF0FCFB2-CB12-44BA-BBB5-1BE0BCFCD14C}.Debug|x86.Build.0 = Debug|Any CPU
110110
{DF0FCFB2-CB12-44BA-BBB5-1BE0BCFCD14C}.Release|Any CPU.ActiveCfg = Release|Any CPU
111+
{DF0FCFB2-CB12-44BA-BBB5-1BE0BCFCD14C}.Release|Any CPU.Build.0 = Release|Any CPU
111112
{DF0FCFB2-CB12-44BA-BBB5-1BE0BCFCD14C}.Release|x64.ActiveCfg = Release|Any CPU
112113
{DF0FCFB2-CB12-44BA-BBB5-1BE0BCFCD14C}.Release|x64.Build.0 = Release|Any CPU
113114
{DF0FCFB2-CB12-44BA-BBB5-1BE0BCFCD14C}.Release|x86.ActiveCfg = Release|Any CPU

benchmarks/BenchmarkResource.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Benchmarks
44
{
5-
public class BenchmarkResource : Identifiable
5+
public sealed class BenchmarkResource : Identifiable
66
{
77
[Attr(BenchmarkResourcePublicNames.NameAttr)]
88
public string Name { get; set; }
@@ -17,7 +17,7 @@ public class SubResource : Identifiable
1717
public string Value { get; set; }
1818
}
1919

20-
public static class BenchmarkResourcePublicNames
20+
internal static class BenchmarkResourcePublicNames
2121
{
2222
public const string NameAttr = "full-name";
2323
public const string Type = "simple-types";

benchmarks/Benchmarks.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
<ItemGroup>
77
<PackageReference Include="BenchmarkDotNet" Version="0.12.0" />
88
<PackageReference Include="moq" Version="$(MoqVersion)" />
9-
<PackageReference Include="xunit" Version="$(xUnitVersion)" />
109
</ItemGroup>
1110
<ItemGroup>
1211
<ProjectReference Include="../src/JsonApiDotNetCore/JsonApiDotNetCore.csproj" />

benchmarks/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55

66
namespace Benchmarks
77
{
8-
class Program
8+
internal class Program
99
{
10-
static void Main(string[] args)
10+
private static void Main(string[] args)
1111
{
1212
var switcher = new BenchmarkSwitcher(new[]
1313
{

src/Examples/GettingStarted/Controllers/ArticlesController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace GettingStarted
88
{
9-
public class ArticlesController : JsonApiController<Article>
9+
public sealed class ArticlesController : JsonApiController<Article>
1010
{
1111
public ArticlesController(
1212
IJsonApiOptions jsonApiOptions,

src/Examples/GettingStarted/Controllers/PeopleController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace GettingStarted
88
{
9-
public class PeopleController : JsonApiController<Person>
9+
public sealed class PeopleController : JsonApiController<Person>
1010
{
1111
public PeopleController(
1212
IJsonApiOptions jsonApiOptions,

src/Examples/GettingStarted/Models/Article.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
namespace GettingStarted.Models
44
{
5-
public class Article : Identifiable
5+
public sealed class Article : Identifiable
66
{
77
[Attr]
88
public string Title { get; set; }
99
[HasOne]
1010
public Person Author { get; set; }
1111
public int AuthorId { get; set; }
1212
}
13-
}
13+
}

src/Examples/GettingStarted/Models/Person.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33

44
namespace GettingStarted.Models
55
{
6-
public class Person : Identifiable
6+
public sealed class Person : Identifiable
77
{
88
[Attr]
99
public string Name { get; set; }
1010
[HasMany]
1111
public List<Article> Articles { get; set; }
1212
}
13-
}
13+
}

src/Examples/GettingStarted/ResourceDefinitionExample/Model.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace GettingStarted.ResourceDefinitionExample
44
{
5-
public class Model : Identifiable
5+
public sealed class Model : Identifiable
66
{
77
[Attr]
88
public string DoNotExpose { get; set; }

src/Examples/GettingStarted/ResourceDefinitionExample/ModelDefinition.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System.Collections.Generic;
21
using JsonApiDotNetCore.Internal.Contracts;
32
using JsonApiDotNetCore.Models;
43

src/Examples/GettingStarted/ResourceDefinitionExample/ModelsController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace GettingStarted.ResourceDefinitionExample
77
{
8-
public class ModelsController : JsonApiController<Model>
8+
public sealed class ModelsController : JsonApiController<Model>
99
{
1010
public ModelsController(
1111
IJsonApiOptions jsonApiOptions,

src/Examples/GettingStarted/Startup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace GettingStarted
77
{
8-
public class Startup
8+
public sealed class Startup
99
{
1010
public void ConfigureServices(IServiceCollection services)
1111
{

src/Examples/JsonApiDotNetCoreExample/Controllers/ArticlesController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace JsonApiDotNetCoreExample.Controllers
88
{
9-
public class ArticlesController : JsonApiController<Article>
9+
public sealed class ArticlesController : JsonApiController<Article>
1010
{
1111
public ArticlesController(
1212
IJsonApiOptions jsonApiOptions,

src/Examples/JsonApiDotNetCoreExample/Controllers/CamelCasedModelsController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace JsonApiDotNetCoreExample.Controllers
88
{
9-
public class KebabCasedModelsController : JsonApiController<KebabCasedModel>
9+
public sealed class KebabCasedModelsController : JsonApiController<KebabCasedModel>
1010
{
1111
public KebabCasedModelsController(
1212
IJsonApiOptions jsonApiOptions,

src/Examples/JsonApiDotNetCoreExample/Controllers/PassportsController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace JsonApiDotNetCoreExample.Controllers
88
{
9-
public class PassportsController : JsonApiController<Passport>
9+
public sealed class PassportsController : JsonApiController<Passport>
1010
{
1111
public PassportsController(
1212
IJsonApiOptions jsonApiOptions,

src/Examples/JsonApiDotNetCoreExample/Controllers/PeopleController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace JsonApiDotNetCoreExample.Controllers
88
{
9-
public class PeopleController : JsonApiController<Person>
9+
public sealed class PeopleController : JsonApiController<Person>
1010
{
1111
public PeopleController(
1212
IJsonApiOptions jsonApiOptions,

src/Examples/JsonApiDotNetCoreExample/Controllers/PersonRolesController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace JsonApiDotNetCoreExample.Controllers
88
{
9-
public class PersonRolesController : JsonApiController<PersonRole>
9+
public sealed class PersonRolesController : JsonApiController<PersonRole>
1010
{
1111
public PersonRolesController(
1212
IJsonApiOptions jsonApiOptions,

src/Examples/JsonApiDotNetCoreExample/Controllers/TagsController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace JsonApiDotNetCoreExample.Controllers
88
{
9-
public class TagsController : JsonApiController<Tag>
9+
public sealed class TagsController : JsonApiController<Tag>
1010
{
1111
public TagsController(
1212
IJsonApiOptions jsonApiOptions,

src/Examples/JsonApiDotNetCoreExample/Controllers/TestValuesController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public class TestValuesController : ControllerBase
88
[HttpGet]
99
public IActionResult Get()
1010
{
11-
var result = new string[] { "value" };
11+
var result = new[] { "value" };
1212
return Ok(result);
1313
}
1414
}

src/Examples/JsonApiDotNetCoreExample/Controllers/TodoCollectionsController.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212

1313
namespace JsonApiDotNetCoreExample.Controllers
1414
{
15-
public class TodoCollectionsController : JsonApiController<TodoItemCollection, Guid>
15+
public sealed class TodoCollectionsController : JsonApiController<TodoItemCollection, Guid>
1616
{
17-
readonly IDbContextResolver _dbResolver;
17+
private readonly IDbContextResolver _dbResolver;
1818

1919
public TodoCollectionsController(
2020
IJsonApiOptions jsonApiOptions,

src/Examples/JsonApiDotNetCoreExample/Controllers/TodoItemsController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace JsonApiDotNetCoreExample.Controllers
88
{
9-
public class TodoItemsController : JsonApiController<TodoItem>
9+
public sealed class TodoItemsController : JsonApiController<TodoItem>
1010
{
1111
public TodoItemsController(
1212
IJsonApiOptions jsonApiOptions,

src/Examples/JsonApiDotNetCoreExample/Controllers/TodoItemsCustomController.cs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,31 +28,28 @@ public CustomJsonApiController(
2828
IJsonApiOptions options,
2929
IResourceService<T, int> resourceService,
3030
ILoggerFactory loggerFactory)
31-
: base(options, resourceService, loggerFactory)
31+
: base(options, resourceService)
3232
{
3333
}
3434
}
3535

3636
public class CustomJsonApiController<T, TId>
3737
: ControllerBase where T : class, IIdentifiable<TId>
3838
{
39-
private readonly ILogger _logger;
4039
private readonly IJsonApiOptions _options;
4140
private readonly IResourceService<T, TId> _resourceService;
4241

43-
protected IActionResult Forbidden()
42+
private IActionResult Forbidden()
4443
{
4544
return new StatusCodeResult(403);
4645
}
4746

4847
public CustomJsonApiController(
4948
IJsonApiOptions options,
50-
IResourceService<T, TId> resourceService,
51-
ILoggerFactory loggerFactory)
49+
IResourceService<T, TId> resourceService)
5250
{
5351
_options = options;
5452
_resourceService = resourceService;
55-
_logger = loggerFactory.CreateLogger<JsonApiController<T, TId>>();
5653
}
5754

5855
public CustomJsonApiController(
@@ -62,14 +59,14 @@ public CustomJsonApiController(
6259
}
6360

6461
[HttpGet]
65-
public virtual async Task<IActionResult> GetAsync()
62+
public async Task<IActionResult> GetAsync()
6663
{
6764
var entities = await _resourceService.GetAsync();
6865
return Ok(entities);
6966
}
7067

7168
[HttpGet("{id}")]
72-
public virtual async Task<IActionResult> GetAsync(TId id)
69+
public async Task<IActionResult> GetAsync(TId id)
7370
{
7471
var entity = await _resourceService.GetAsync(id);
7572

@@ -80,7 +77,7 @@ public virtual async Task<IActionResult> GetAsync(TId id)
8077
}
8178

8279
[HttpGet("{id}/relationships/{relationshipName}")]
83-
public virtual async Task<IActionResult> GetRelationshipsAsync(TId id, string relationshipName)
80+
public async Task<IActionResult> GetRelationshipsAsync(TId id, string relationshipName)
8481
{
8582
var relationship = _resourceService.GetRelationshipAsync(id, relationshipName);
8683
if (relationship == null)
@@ -90,14 +87,14 @@ public virtual async Task<IActionResult> GetRelationshipsAsync(TId id, string re
9087
}
9188

9289
[HttpGet("{id}/{relationshipName}")]
93-
public virtual async Task<IActionResult> GetRelationshipAsync(TId id, string relationshipName)
90+
public async Task<IActionResult> GetRelationshipAsync(TId id, string relationshipName)
9491
{
9592
var relationship = await _resourceService.GetRelationshipAsync(id, relationshipName);
9693
return Ok(relationship);
9794
}
9895

9996
[HttpPost]
100-
public virtual async Task<IActionResult> PostAsync([FromBody] T entity)
97+
public async Task<IActionResult> PostAsync([FromBody] T entity)
10198
{
10299
if (entity == null)
103100
return UnprocessableEntity();
@@ -111,7 +108,7 @@ public virtual async Task<IActionResult> PostAsync([FromBody] T entity)
111108
}
112109

113110
[HttpPatch("{id}")]
114-
public virtual async Task<IActionResult> PatchAsync(TId id, [FromBody] T entity)
111+
public async Task<IActionResult> PatchAsync(TId id, [FromBody] T entity)
115112
{
116113
if (entity == null)
117114
return UnprocessableEntity();
@@ -125,14 +122,14 @@ public virtual async Task<IActionResult> PatchAsync(TId id, [FromBody] T entity)
125122
}
126123

127124
[HttpPatch("{id}/relationships/{relationshipName}")]
128-
public virtual async Task<IActionResult> PatchRelationshipsAsync(TId id, string relationshipName, [FromBody] List<ResourceObject> relationships)
125+
public async Task<IActionResult> PatchRelationshipsAsync(TId id, string relationshipName, [FromBody] List<ResourceObject> relationships)
129126
{
130127
await _resourceService.UpdateRelationshipsAsync(id, relationshipName, relationships);
131128
return Ok();
132129
}
133130

134131
[HttpDelete("{id}")]
135-
public virtual async Task<IActionResult> DeleteAsync(TId id)
132+
public async Task<IActionResult> DeleteAsync(TId id)
136133
{
137134
var wasDeleted = await _resourceService.DeleteAsync(id);
138135

src/Examples/JsonApiDotNetCoreExample/Controllers/UsersController.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace JsonApiDotNetCoreExample.Controllers
88
{
9-
public class UsersController : JsonApiController<User>
9+
public sealed class UsersController : JsonApiController<User>
1010
{
1111
public UsersController(
1212
IJsonApiOptions jsonApiOptions,
@@ -16,7 +16,7 @@ public UsersController(
1616
{ }
1717
}
1818

19-
public class SuperUsersController : JsonApiController<SuperUser>
19+
public sealed class SuperUsersController : JsonApiController<SuperUser>
2020
{
2121
public SuperUsersController(
2222
IJsonApiOptions jsonApiOptions,

src/Examples/JsonApiDotNetCoreExample/Data/AppDbContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace JsonApiDotNetCoreExample.Data
55
{
6-
public class AppDbContext : DbContext
6+
public sealed class AppDbContext : DbContext
77
{
88
public DbSet<TodoItem> TodoItems { get; set; }
99
public DbSet<Passport> Passports { get; set; }

src/Examples/JsonApiDotNetCoreExample/Models/Article.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace JsonApiDotNetCoreExample.Models
66
{
7-
public class Article : Identifiable
7+
public sealed class Article : Identifiable
88
{
99
[Attr]
1010
public string Name { get; set; }

src/Examples/JsonApiDotNetCoreExample/Models/ArticleTag.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace JsonApiDotNetCoreExample.Models
44
{
5-
public class ArticleTag
5+
public sealed class ArticleTag
66
{
77
public int ArticleId { get; set; }
88
public Article Article { get; set; }
@@ -24,4 +24,4 @@ public class IdentifiableArticleTag : Identifiable
2424

2525
public string SomeMetaData { get; set; }
2626
}
27-
}
27+
}

src/Examples/JsonApiDotNetCoreExample/Models/Author.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace JsonApiDotNetCoreExample.Models
55
{
6-
public class Author : Identifiable
6+
public sealed class Author : Identifiable
77
{
88
[Attr]
99
public string Name { get; set; }

src/Examples/JsonApiDotNetCoreExample/Models/Passport.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
namespace JsonApiDotNetCoreExample.Models
44
{
5-
public class Passport : Identifiable
5+
public sealed class Passport : Identifiable
66
{
7-
public virtual int? SocialSecurityNumber { get; set; }
8-
public virtual bool IsLocked { get; set; }
7+
public int? SocialSecurityNumber { get; set; }
8+
public bool IsLocked { get; set; }
99

1010
[HasOne]
11-
public virtual Person Person { get; set; }
11+
public Person Person { get; set; }
1212
}
13-
}
13+
}

0 commit comments

Comments
 (0)