Skip to content

Commit 2945cee

Browse files
committed
Enable C# 8 nullable reference types
1 parent d418a8c commit 2945cee

34 files changed

+235
-246
lines changed

Benchmarks/Serilog.Exceptions.Benchmark/BenchmarkException.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ protected BenchmarkException(
2727
{
2828
}
2929

30-
public string ParamString { get; set; }
30+
public string? ParamString { get; set; }
3131

3232
public int ParamInt { get; set; }
3333

34-
public Point Point { get; set; }
34+
public Point? Point { get; set; }
3535
}
3636
}

Benchmarks/Serilog.Exceptions.Benchmark/BenchmarkExceptionDestructurer.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,18 @@ public class BenchmarkExceptionDestructurer : ExceptionDestructurer
1818
public override void Destructure(
1919
Exception exception,
2020
IExceptionPropertiesBag propertiesBag,
21-
Func<Exception, IReadOnlyDictionary<string, object>> destructureException)
21+
Func<Exception, IReadOnlyDictionary<string, object?>?> destructureException)
2222
{
2323
base.Destructure(exception, propertiesBag, destructureException);
2424

2525
#pragma warning disable CA1062 // Validate arguments of public methods
2626
var benchmarkException = (BenchmarkException)exception;
2727
propertiesBag.AddProperty("ParamString", benchmarkException.ParamString);
2828
propertiesBag.AddProperty("ParamInt", benchmarkException.ParamInt);
29-
propertiesBag.AddProperty("Point", new Dictionary<string, object>
29+
propertiesBag.AddProperty("Point", new Dictionary<string, object?>
3030
{
31-
{ "X", benchmarkException.Point.X },
32-
{ "Y", benchmarkException.Point.Y },
31+
{ "X", benchmarkException.Point?.X },
32+
{ "Y", benchmarkException.Point?.Y },
3333
});
3434
#pragma warning restore CA1062 // Validate arguments of public methods
3535
}

Benchmarks/Serilog.Exceptions.Benchmark/DestructuringBenchmark.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class DestructuringBenchmark
1919
{
2020
private readonly ReflectionBasedDestructurer reflectionBasedDestructurer = new(10);
2121
private readonly BenchmarkExceptionDestructurer benchmarkExceptionDestructurer = new();
22-
private BenchmarkException benchmarkException;
22+
private BenchmarkException benchmarkException = default!;
2323

2424
[GlobalSetup]
2525
public void Setup()
@@ -39,36 +39,36 @@ public void Setup()
3939
}
4040
}
4141

42-
public IReadOnlyDictionary<string, object> DestructureUsingReflectionDestructurer(Exception ex)
42+
public IReadOnlyDictionary<string, object?> DestructureUsingReflectionDestructurer(Exception ex)
4343
{
4444
var bag = new ExceptionPropertiesBag(ex);
4545

4646
this.reflectionBasedDestructurer.Destructure(
4747
ex,
4848
bag,
49-
null);
49+
null!);
5050

5151
return bag.GetResultDictionary();
5252
}
5353

5454
[Benchmark]
55-
public IReadOnlyDictionary<string, object> ReflectionDestructurer() =>
55+
public IReadOnlyDictionary<string, object?> ReflectionDestructurer() =>
5656
this.DestructureUsingReflectionDestructurer(this.benchmarkException);
5757

58-
public IReadOnlyDictionary<string, object> DestructureUsingCustomDestructurer(Exception ex)
58+
public IReadOnlyDictionary<string, object?> DestructureUsingCustomDestructurer(Exception ex)
5959
{
6060
var bag = new ExceptionPropertiesBag(ex);
6161

6262
this.benchmarkExceptionDestructurer.Destructure(
6363
ex,
6464
bag,
65-
null);
65+
null!);
6666

6767
return bag.GetResultDictionary();
6868
}
6969

7070
[Benchmark]
71-
public IReadOnlyDictionary<string, object> CustomDestructurer() =>
71+
public IReadOnlyDictionary<string, object?> CustomDestructurer() =>
7272
this.DestructureUsingCustomDestructurer(this.benchmarkException);
7373
}
7474
}

Benchmarks/Serilog.Exceptions.Benchmark/ExceptionPropertiesBag.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,26 @@ namespace Serilog.Exceptions.Benchmark
88
internal class ExceptionPropertiesBag : IExceptionPropertiesBag
99
{
1010
private readonly Exception exception;
11-
private readonly IExceptionPropertyFilter filter;
12-
private readonly Dictionary<string, object> properties = new();
11+
private readonly IExceptionPropertyFilter? filter;
12+
private readonly Dictionary<string, object?> properties = new();
1313

1414
// We keep a note on whether the results were collected to be sure that
1515
// after that there are no changes. This is the application of fail-fast principle.
1616
private bool resultsCollected;
1717

18-
public ExceptionPropertiesBag(Exception exception, IExceptionPropertyFilter filter = null)
18+
public ExceptionPropertiesBag(Exception exception, IExceptionPropertyFilter? filter = null)
1919
{
2020
this.exception = exception ?? throw new ArgumentNullException(nameof(exception));
2121
this.filter = filter;
2222
}
2323

24-
public IReadOnlyDictionary<string, object> GetResultDictionary()
24+
public IReadOnlyDictionary<string, object?> GetResultDictionary()
2525
{
2626
this.resultsCollected = true;
2727
return this.properties;
2828
}
2929

30-
public void AddProperty(string key, object value)
30+
public void AddProperty(string key, object? value)
3131
{
3232
if (key is null)
3333
{

Directory.Build.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<LangVersion>latest</LangVersion>
55
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
66
<AnalysisLevel>latest</AnalysisLevel>
7+
<Nullable>enable</Nullable>
78
<NeutralLanguage>en-GB</NeutralLanguage>
89
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
910
</PropertyGroup>

Source/Serilog.Exceptions.EntityFrameworkCore/Destructurers/DbUpdateExceptionDestructurer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class DbUpdateExceptionDestructurer : ExceptionDestructurer
2020
public override void Destructure(
2121
Exception exception,
2222
IExceptionPropertiesBag propertiesBag,
23-
Func<Exception, IReadOnlyDictionary<string, object>> destructureException)
23+
Func<Exception, IReadOnlyDictionary<string, object?>?> destructureException)
2424
{
2525
base.Destructure(exception, propertiesBag, destructureException);
2626

Source/Serilog.Exceptions.MsSqlServer/Destructurers/SqlExceptionDestructurer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class SqlExceptionDestructurer : ExceptionDestructurer
2020
public override void Destructure(
2121
Exception exception,
2222
IExceptionPropertiesBag propertiesBag,
23-
Func<Exception, IReadOnlyDictionary<string, object>> destructureException)
23+
Func<Exception, IReadOnlyDictionary<string, object?>?> destructureException)
2424
{
2525
base.Destructure(exception, propertiesBag, destructureException);
2626

Source/Serilog.Exceptions.SqlServer/Destructurers/SqlExceptionDestructurer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class SqlExceptionDestructurer : ExceptionDestructurer
2020
public override void Destructure(
2121
Exception exception,
2222
IExceptionPropertiesBag propertiesBag,
23-
Func<Exception, IReadOnlyDictionary<string, object>> destructureException)
23+
Func<Exception, IReadOnlyDictionary<string, object?>?> destructureException)
2424
{
2525
base.Destructure(exception, propertiesBag, destructureException);
2626

@@ -36,4 +36,4 @@ public override void Destructure(
3636
#pragma warning restore CA1062 // Validate arguments of public methods
3737
}
3838
}
39-
}
39+
}

Source/Serilog.Exceptions/Core/DestructuringOptionsBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public class DestructuringOptionsBuilder : IDestructuringOptions
6767
/// <summary>
6868
/// Gets a global filter, that will be applied to every destructured property just before it is added to the result.
6969
/// </summary>
70-
public IExceptionPropertyFilter Filter { get; private set; }
70+
public IExceptionPropertyFilter? Filter { get; private set; }
7171

7272
/// <summary>
7373
/// Accumulates destructurers to be used by <see cref="ExceptionEnricher"/>.

Source/Serilog.Exceptions/Core/ExceptionEnricher.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
7474
}
7575
}
7676

77-
private IReadOnlyDictionary<string, object> DestructureException(Exception exception)
77+
private IReadOnlyDictionary<string, object?>? DestructureException(Exception exception)
7878
{
7979
var exceptionType = exception.GetType();
8080

0 commit comments

Comments
 (0)