Skip to content

Commit d226f0e

Browse files
committed
First round of code cleanup and modernization
1 parent 12b78ed commit d226f0e

File tree

129 files changed

+427
-1160
lines changed

Some content is hidden

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

129 files changed

+427
-1160
lines changed

.editorconfig

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,79 @@ dotnet_naming_symbols.instance_fields.applicable_kinds = field
131131

132132
dotnet_naming_style.instance_field_style.capitalization = camel_case
133133
dotnet_naming_style.instance_field_style.required_prefix = _
134+
csharp_indent_labels = one_less_than_current
135+
csharp_using_directive_placement = outside_namespace:silent
136+
csharp_prefer_simple_using_statement = true:suggestion
137+
csharp_style_namespace_declarations = block_scoped:silent
138+
csharp_style_prefer_method_group_conversion = true:silent
139+
csharp_style_prefer_top_level_statements = true:silent
140+
csharp_style_prefer_primary_constructors = true:suggestion
141+
csharp_style_expression_bodied_operators = false:silent
142+
csharp_style_expression_bodied_indexers = true:silent
143+
csharp_style_expression_bodied_accessors = true:silent
144+
csharp_style_expression_bodied_lambdas = true:silent
145+
csharp_style_expression_bodied_local_functions = false:silent
146+
csharp_style_throw_expression = true:suggestion
147+
csharp_style_prefer_null_check_over_type_check = true:suggestion
148+
csharp_space_around_binary_operators = before_and_after
149+
csharp_style_prefer_local_over_anonymous_function = true:suggestion
150+
csharp_style_prefer_index_operator = true:suggestion
151+
csharp_style_prefer_range_operator = true:suggestion
152+
csharp_style_implicit_object_creation_when_type_is_apparent = true:suggestion
153+
csharp_style_prefer_tuple_swap = true:suggestion
154+
csharp_style_prefer_utf8_string_literals = true:suggestion
155+
csharp_style_inlined_variable_declaration = true:suggestion
156+
csharp_style_deconstructed_variable_declaration = true:suggestion
157+
csharp_style_unused_value_assignment_preference = discard_variable:suggestion
158+
csharp_style_unused_value_expression_statement_preference = discard_variable:silent
159+
csharp_style_prefer_readonly_struct = true:suggestion
160+
csharp_prefer_static_local_function = true:suggestion
161+
csharp_style_prefer_readonly_struct_member = true:suggestion
162+
csharp_style_allow_embedded_statements_on_same_line_experimental = true:silent
163+
csharp_style_allow_blank_lines_between_consecutive_braces_experimental = true:silent
164+
csharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental = true:silent
165+
csharp_style_allow_blank_line_after_token_in_conditional_expression_experimental = true:silent
166+
csharp_style_allow_blank_line_after_token_in_arrow_expression_clause_experimental = true:silent
167+
csharp_style_conditional_delegate_call = true:suggestion
168+
csharp_style_prefer_switch_expression = true:suggestion
169+
csharp_style_prefer_pattern_matching = true:silent
170+
csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
171+
csharp_style_prefer_not_pattern = true:suggestion
172+
csharp_style_prefer_extended_property_pattern = true:suggestion
173+
174+
[*.{cs,vb}]
175+
dotnet_style_operator_placement_when_wrapping = beginning_of_line
176+
tab_width = 4
177+
indent_size = 4
178+
end_of_line = crlf
179+
dotnet_style_coalesce_expression = true:suggestion
180+
dotnet_style_null_propagation = true:suggestion
181+
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion
182+
dotnet_style_prefer_auto_properties = true:silent
183+
dotnet_style_object_initializer = true:suggestion
184+
dotnet_style_collection_initializer = true:suggestion
185+
dotnet_style_prefer_simplified_boolean_expressions = true:suggestion
186+
dotnet_style_prefer_conditional_expression_over_assignment = true:silent
187+
dotnet_style_prefer_conditional_expression_over_return = true:silent
188+
dotnet_style_explicit_tuple_names = true:suggestion
189+
dotnet_style_prefer_inferred_tuple_names = true:suggestion
190+
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
191+
dotnet_style_prefer_compound_assignment = true:suggestion
192+
dotnet_style_prefer_simplified_interpolation = true:suggestion
193+
dotnet_style_prefer_collection_expression = when_types_loosely_match:suggestion
194+
dotnet_style_namespace_match_folder = true:suggestion
195+
dotnet_style_readonly_field = true:suggestion
196+
dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion
197+
dotnet_style_predefined_type_for_member_access = true:suggestion
198+
dotnet_style_require_accessibility_modifiers = never:silent
199+
dotnet_style_allow_multiple_blank_lines_experimental = true:silent
200+
dotnet_style_allow_statement_immediately_after_block_experimental = true:silent
201+
dotnet_code_quality_unused_parameters = all:suggestion
202+
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:silent
203+
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:silent
204+
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:silent
205+
dotnet_style_parentheses_in_other_operators = never_if_unnecessary:silent
206+
dotnet_style_qualification_for_field = false:suggestion
207+
dotnet_style_qualification_for_property = false:suggestion
208+
dotnet_style_qualification_for_method = false:suggestion
209+
dotnet_style_qualification_for_event = false:silent

benchmarks/EntityFrameworkCore.Triggered.Benchmarks/ApplicationContext.cs

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,9 @@ public interface IApplicationContextContract : IDisposable
4747
DbSet<StudentCourse> StudentCourses { get; set; }
4848
}
4949

50-
public class ApplicationContext : DbContext, IApplicationContextContract
50+
public class ApplicationContext(DbContextOptions<ApplicationContext> options) : DbContext(options), IApplicationContextContract
5151
{
52-
public ApplicationContext(DbContextOptions<ApplicationContext> options) : base(options)
53-
{
54-
}
55-
56-
protected override void OnModelCreating(ModelBuilder modelBuilder)
57-
{
58-
modelBuilder.Entity<StudentCourse>().HasKey(x => new { x.StudentId, x.CourseId });
59-
}
52+
protected override void OnModelCreating(ModelBuilder modelBuilder) => modelBuilder.Entity<StudentCourse>().HasKey(x => new { x.StudentId, x.CourseId });
6053

6154
public DbSet<Student> Students { get; set; }
6255

@@ -65,16 +58,9 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
6558
public DbSet<StudentCourse> StudentCourses { get; set; }
6659
}
6760

68-
public class TriggeredApplicationContext : DbContext, IApplicationContextContract
61+
public class TriggeredApplicationContext(DbContextOptions<TriggeredApplicationContext> options) : DbContext(options), IApplicationContextContract
6962
{
70-
public TriggeredApplicationContext(DbContextOptions<TriggeredApplicationContext> options) : base(options)
71-
{
72-
}
73-
74-
protected override void OnModelCreating(ModelBuilder modelBuilder)
75-
{
76-
modelBuilder.Entity<StudentCourse>().HasKey(x => new { x.StudentId, x.CourseId });
77-
}
63+
protected override void OnModelCreating(ModelBuilder modelBuilder) => modelBuilder.Entity<StudentCourse>().HasKey(x => new { x.StudentId, x.CourseId });
7864

7965
public DbSet<Student> Students { get; set; }
8066

benchmarks/EntityFrameworkCore.Triggered.Benchmarks/EmbracingFeaturesBenchmarks.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ public class EmbracingFeaturesBenchmarks
1212
private IServiceProvider _serviceProvider;
1313

1414
[GlobalSetup]
15-
public void GlobalSetup()
16-
{
17-
_serviceProvider = new ServiceCollection()
15+
public void GlobalSetup() => _serviceProvider = new ServiceCollection()
1816
.AddDbContext<ApplicationContext>(options => {
1917
options
2018
.UseInMemoryDatabase(nameof(WithDbContext));
@@ -29,8 +27,6 @@ public void GlobalSetup()
2927
})
3028
.BuildServiceProvider();
3129

32-
}
33-
3430
[Params(50)]
3531
public int OuterBatches;
3632

benchmarks/EntityFrameworkCore.Triggered.Benchmarks/PlainOverheadBenchmarks.cs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ public class PlainOverheadBenchmarks
1212
IServiceProvider _serviceProvider;
1313

1414
[GlobalSetup]
15-
public void GlobalSetup()
16-
{
17-
_serviceProvider = new ServiceCollection()
15+
public void GlobalSetup() => _serviceProvider = new ServiceCollection()
1816
.AddDbContext<ApplicationContext>(options => {
1917
options
2018
.UseInMemoryDatabase(nameof(WithDbContext));
@@ -25,7 +23,6 @@ public void GlobalSetup()
2523
.UseTriggers();
2624
})
2725
.BuildServiceProvider();
28-
}
2926

3027
[Params(50)]
3128
public int OuterBatches;
@@ -89,15 +86,9 @@ void Execute<TApplicationContext>()
8986
}
9087

9188
[Benchmark(Baseline = true)]
92-
public void WithDbContext()
93-
{
94-
Execute<ApplicationContext>();
95-
}
89+
public void WithDbContext() => Execute<ApplicationContext>();
9690

9791
[Benchmark]
98-
public void WithTriggeredDbContext()
99-
{
100-
Execute<TriggeredApplicationContext>();
101-
}
92+
public void WithTriggeredDbContext() => Execute<TriggeredApplicationContext>();
10293
}
10394
}

benchmarks/EntityFrameworkCore.Triggered.Benchmarks/Program.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ namespace EntityFrameworkCore.Triggered.Benchmarks
55
{
66
public class Program
77
{
8-
public static void Main(string[] args)
9-
{
10-
BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args, DefaultConfig.Instance.WithOption(ConfigOptions.DisableOptimizationsValidator, true));
11-
}
8+
public static void Main(string[] args) => BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args, DefaultConfig.Instance.WithOption(ConfigOptions.DisableOptimizationsValidator, true));
129
}
1310
}
Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
using System;
2-
using System.Threading;
3-
using System.Threading.Tasks;
42

53
namespace EntityFrameworkCore.Triggered.Benchmarks.Triggers
64
{
75
public class SetStudentRegistrationDateTrigger : IBeforeSaveTrigger<Student>
86
{
9-
public void BeforeSave(ITriggerContext<Student> context)
10-
{
11-
context.Entity.RegistrationDate = DateTimeOffset.Now;
12-
}
7+
public void BeforeSave(ITriggerContext<Student> context) => context.Entity.RegistrationDate = DateTimeOffset.Now;
138
}
149
}

benchmarks/EntityFrameworkCore.Triggered.Benchmarks/Triggers/SignStudentUpForMandatoryCourses.cs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,10 @@
11
using System.Linq;
2-
using System.Threading;
3-
using System.Threading.Tasks;
42

53
namespace EntityFrameworkCore.Triggered.Benchmarks.Triggers
64
{
7-
public class SignStudentUpForMandatoryCourses : IBeforeSaveTrigger<Student>
5+
public class SignStudentUpForMandatoryCourses(TriggeredApplicationContext applicationContext) : IBeforeSaveTrigger<Student>
86
{
9-
readonly TriggeredApplicationContext _applicationContext;
10-
11-
public SignStudentUpForMandatoryCourses(TriggeredApplicationContext applicationContext)
12-
{
13-
_applicationContext = applicationContext;
14-
}
7+
readonly TriggeredApplicationContext _applicationContext = applicationContext;
158

169
public void BeforeSave(ITriggerContext<Student> context)
1710
{

samples/1 - HelloWorld/Triggers/StudentAssignRegistrationDate.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
using System;
2-
using System.Threading;
3-
using System.Threading.Tasks;
42
using EntityFrameworkCore.Triggered;
53

64
namespace PrimarySchool.Triggers

samples/2 - PrimarySchool/ApplicationDbContext.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,8 @@ public class StudentCourse
3434
}
3535

3636

37-
public class ApplicationDbContext : DbContext
37+
public class ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : DbContext(options)
3838
{
39-
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options)
40-
{
41-
42-
}
43-
4439
protected override void OnModelCreating(ModelBuilder modelBuilder)
4540
{
4641
modelBuilder.Entity<StudentCourse>()

samples/2 - PrimarySchool/Triggers/StudentSignupToMandatoryCourses.cs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,11 @@
11
using System.Linq;
2-
using System.Threading;
3-
using System.Threading.Tasks;
42
using EntityFrameworkCore.Triggered;
53

64
namespace PrimarySchool.Triggers
75
{
8-
public class StudentSignupToMandatoryCourses : IBeforeSaveTrigger<Student>
6+
public class StudentSignupToMandatoryCourses(ApplicationDbContext applicationContext) : IBeforeSaveTrigger<Student>
97
{
10-
readonly ApplicationDbContext _applicationContext;
11-
12-
public StudentSignupToMandatoryCourses(ApplicationDbContext applicationContext)
13-
{
14-
_applicationContext = applicationContext;
15-
}
8+
readonly ApplicationDbContext _applicationContext = applicationContext;
169

1710
public void BeforeSave(ITriggerContext<Student> context)
1811
{

0 commit comments

Comments
 (0)