Skip to content

Commit f196d4a

Browse files
committed
Nullable enable
1 parent fcf1cff commit f196d4a

29 files changed

+122
-108
lines changed

src/Serilog.Expressions/Expressions/Compilation/Linq/Intrinsics.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ static class Intrinsics
99
{
1010
static readonly LogEventPropertyValue NegativeOne = new ScalarValue(-1);
1111

12-
public static LogEventPropertyValue ConstructSequenceValue(LogEventPropertyValue[] elements)
12+
public static LogEventPropertyValue? ConstructSequenceValue(LogEventPropertyValue[] elements)
1313
{
1414
// Avoid upsetting Serilog's (currently) fragile `SequenceValue.Render()`.
1515
if (elements.Any(el => el == null))
@@ -24,7 +24,7 @@ public static bool CoerceToScalarBoolean(LogEventPropertyValue value)
2424
return false;
2525
}
2626

27-
public static LogEventPropertyValue IndexOfMatch(LogEventPropertyValue value, Regex regex)
27+
public static LogEventPropertyValue? IndexOfMatch(LogEventPropertyValue value, Regex regex)
2828
{
2929
if (value is ScalarValue scalar &&
3030
scalar.Value is string s)
@@ -38,15 +38,15 @@ public static LogEventPropertyValue IndexOfMatch(LogEventPropertyValue value, Re
3838
return null;
3939
}
4040

41-
public static LogEventPropertyValue GetPropertyValue(LogEvent context, string propertyName)
41+
public static LogEventPropertyValue? GetPropertyValue(LogEvent context, string propertyName)
4242
{
4343
if (!context.Properties.TryGetValue(propertyName, out var value))
4444
return null;
4545

4646
return value;
4747
}
4848

49-
public static LogEventPropertyValue TryGetStructurePropertyValue(LogEventPropertyValue maybeStructure, string name)
49+
public static LogEventPropertyValue? TryGetStructurePropertyValue(LogEventPropertyValue maybeStructure, string name)
5050
{
5151
if (maybeStructure is StructureValue sv)
5252
{

src/Serilog.Expressions/Expressions/Compilation/Linq/LinqExpressionCompiler.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@ class LinqExpressionCompiler : SerilogExpressionTransformer<ExpressionBody>
2323
.ToDictionary(m => m.Name, StringComparer.OrdinalIgnoreCase);
2424

2525
static readonly MethodInfo ConstructSequenceValueMethod = typeof(Intrinsics)
26-
.GetMethod(nameof(Intrinsics.ConstructSequenceValue), BindingFlags.Static | BindingFlags.Public);
26+
.GetMethod(nameof(Intrinsics.ConstructSequenceValue), BindingFlags.Static | BindingFlags.Public)!;
2727

2828
static readonly MethodInfo CoerceToScalarBooleanMethod = typeof(Intrinsics)
29-
.GetMethod(nameof(Intrinsics.CoerceToScalarBoolean), BindingFlags.Static | BindingFlags.Public);
29+
.GetMethod(nameof(Intrinsics.CoerceToScalarBoolean), BindingFlags.Static | BindingFlags.Public)!;
3030

3131
static readonly MethodInfo IndexOfMatchMethod = typeof(Intrinsics)
32-
.GetMethod(nameof(Intrinsics.IndexOfMatch), BindingFlags.Static | BindingFlags.Public);
32+
.GetMethod(nameof(Intrinsics.IndexOfMatch), BindingFlags.Static | BindingFlags.Public)!;
3333

3434
static readonly MethodInfo TryGetStructurePropertyValueMethod = typeof(Intrinsics)
35-
.GetMethod(nameof(Intrinsics.TryGetStructurePropertyValue), BindingFlags.Static | BindingFlags.Public);
35+
.GetMethod(nameof(Intrinsics.TryGetStructurePropertyValue), BindingFlags.Static | BindingFlags.Public)!;
3636

3737
ParameterExpression Context { get; } = LX.Variable(typeof(LogEvent), "evt");
3838

src/Serilog.Expressions/Expressions/Compilation/Pattern.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Diagnostics.CodeAnalysis;
12
using Serilog.Events;
23
using Serilog.Expressions.Ast;
34

@@ -12,7 +13,7 @@ public static bool IsAmbientProperty(Expression expression, string name, bool is
1213
px.IsBuiltIn == isBuiltIn;
1314
}
1415

15-
public static bool IsStringConstant(Expression expression, out string value)
16+
public static bool IsStringConstant(Expression expression, [MaybeNullWhen(false)] out string value)
1617
{
1718
if (expression is ConstantExpression cx &&
1819
cx.Constant is ScalarValue sv &&

src/Serilog.Expressions/Expressions/Compilation/Wildcards/WildcardComprehensionTransformer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ protected override Expression Transform(CallExpression lx)
2727

2828
var wildcardPath = lhsIs != null ? target.Operands[0] : target.Operands[1];
2929
var comparand = lhsIs != null ? target.Operands[1] : target.Operands[0];
30-
var indexer = lhsIs ?? rhsIs;
30+
var indexer = lhsIs ?? rhsIs!;
3131

3232
var px = new ParameterExpression("p" + _nextParameter++);
3333
var nestedComparand = NodeReplacer.Replace(wildcardPath, indexer, px);

src/Serilog.Expressions/Expressions/Compilation/Wildcards/WildcardSearch.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,65 +4,65 @@
44

55
namespace Serilog.Expressions.Compilation.Wildcards
66
{
7-
class WildcardSearch : SerilogExpressionTransformer<IndexerExpression>
7+
class WildcardSearch : SerilogExpressionTransformer<IndexerExpression?>
88
{
99
static readonly WildcardSearch Instance = new WildcardSearch();
1010

11-
public static IndexerExpression FindElementAtWildcard(Expression fx)
11+
public static IndexerExpression? FindElementAtWildcard(Expression fx)
1212
{
1313
return Instance.Transform(fx);
1414
}
1515

16-
protected override IndexerExpression Transform(IndexerExpression ix)
16+
protected override IndexerExpression? Transform(IndexerExpression ix)
1717
{
1818
if (ix.Index is IndexerWildcardExpression)
1919
return ix;
2020

2121
return Transform(ix.Receiver);
2222
}
2323

24-
protected override IndexerExpression Transform(ConstantExpression cx)
24+
protected override IndexerExpression? Transform(ConstantExpression cx)
2525
{
2626
return null;
2727
}
2828

29-
protected override IndexerExpression Transform(AmbientPropertyExpression px)
29+
protected override IndexerExpression? Transform(AmbientPropertyExpression px)
3030
{
3131
return null;
3232
}
3333

34-
protected override IndexerExpression Transform(AccessorExpression spx)
34+
protected override IndexerExpression? Transform(AccessorExpression spx)
3535
{
3636
return Transform(spx.Receiver);
3737
}
3838

39-
protected override IndexerExpression Transform(LambdaExpression lmx)
39+
protected override IndexerExpression? Transform(LambdaExpression lmx)
4040
{
4141
return null;
4242
}
4343

44-
protected override IndexerExpression Transform(ParameterExpression prx)
44+
protected override IndexerExpression? Transform(ParameterExpression prx)
4545
{
4646
return null;
4747
}
4848

49-
protected override IndexerExpression Transform(IndexerWildcardExpression wx)
49+
protected override IndexerExpression? Transform(IndexerWildcardExpression wx)
5050
{
5151
// Must be within an indexer
5252
return null;
5353
}
5454

55-
protected override IndexerExpression Transform(ArrayExpression ax)
55+
protected override IndexerExpression? Transform(ArrayExpression ax)
5656
{
5757
return null;
5858
}
5959

60-
protected override IndexerExpression Transform(CallExpression lx)
60+
protected override IndexerExpression? Transform(CallExpression lx)
6161
{
6262
return lx.Operands.Select(Transform).FirstOrDefault(e => e != null);
6363
}
6464

65-
protected override IndexerExpression Transform(IndexOfMatchExpression mx)
65+
protected override IndexerExpression? Transform(IndexOfMatchExpression mx)
6666
{
6767
return Transform(mx.Corpus);
6868
}

src/Serilog.Expressions/Expressions/CompiledExpression.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414

1515
using Serilog.Events;
1616

17-
#nullable enable
18-
1917
namespace Serilog.Expressions
2018
{
2119
/// <summary>

src/Serilog.Expressions/Expressions/ExpressionResult.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public static class ExpressionResult
3030
/// <returns>Returns <c langword="true">true</c> if and only if the
3131
/// <paramref name="value"/> is a scalar Boolean with the
3232
/// value <c langword="true">true</c>. Returns <c langword="false">false</c>, otherwise.</returns>
33-
public static bool IsTrue(LogEventPropertyValue value)
33+
public static bool IsTrue(LogEventPropertyValue? value)
3434
{
3535
return Coerce.IsTrue(value);
3636
}

src/Serilog.Expressions/Expressions/LoggingFilterSwitch.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class LoggingFilterSwitch : ILogEventFilter
2828
// no attempt to synchronize Expression, ToString(), and IsIncluded(),
2929
// for any observer, this at least ensures they won't be permanently out-of-sync for
3030
// all observers.
31-
volatile Tuple<string, CompiledExpression> _filter;
31+
volatile Tuple<string, CompiledExpression>? _filter;
3232

3333
/// <summary>
3434
/// Construct a <see cref="LoggingFilterSwitch"/>, optionally initialized
@@ -38,7 +38,7 @@ public class LoggingFilterSwitch : ILogEventFilter
3838
/// Only expressions that evaluate to <c>true</c> are included
3939
/// by the filter. A <c>null</c> expression will accept all
4040
/// events.</param>
41-
public LoggingFilterSwitch(string expression = null)
41+
public LoggingFilterSwitch(string? expression = null)
4242
{
4343
Expression = expression;
4444
}
@@ -49,7 +49,7 @@ public LoggingFilterSwitch(string expression = null)
4949
/// by the filter. A <c>null</c> expression will accept all
5050
/// events.
5151
/// </summary>
52-
public string Expression
52+
public string? Expression
5353
{
5454
// ReSharper disable once UnusedMember.Global
5555
get

src/Serilog.Expressions/Expressions/Parsing/ExpressionParser.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Diagnostics.CodeAnalysis;
23
using Serilog.Expressions.Ast;
34

45
namespace Serilog.Expressions.Parsing
@@ -15,7 +16,8 @@ public static Expression Parse(string filterExpression)
1516
return root;
1617
}
1718

18-
public static bool TryParse(string filterExpression, out Expression root, out string error)
19+
public static bool TryParse(string filterExpression,
20+
[MaybeNullWhen(false)] out Expression root, [MaybeNullWhen(true)] out string error)
1921
{
2022
if (filterExpression == null) throw new ArgumentNullException(nameof(filterExpression));
2123

src/Serilog.Expressions/Expressions/Runtime/Coerce.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Diagnostics.CodeAnalysis;
23
using System.Linq;
34
using Serilog.Events;
45

@@ -11,7 +12,7 @@ static class Coerce
1112
typeof(float), typeof(uint), typeof(sbyte),
1213
typeof(byte), typeof(short), typeof(ushort), typeof(ulong) };
1314

14-
public static bool Numeric(LogEventPropertyValue value, out decimal numeric)
15+
public static bool Numeric(LogEventPropertyValue? value, out decimal numeric)
1516
{
1617
if (value is ScalarValue sv &&
1718
sv.Value != null &&
@@ -25,7 +26,7 @@ public static bool Numeric(LogEventPropertyValue value, out decimal numeric)
2526
return false;
2627
}
2728

28-
public static bool Boolean(LogEventPropertyValue value, out bool boolean)
29+
public static bool Boolean(LogEventPropertyValue? value, out bool boolean)
2930
{
3031
if (value is ScalarValue sv &&
3132
sv.Value is bool b)
@@ -38,12 +39,12 @@ public static bool Boolean(LogEventPropertyValue value, out bool boolean)
3839
return false;
3940
}
4041

41-
public static bool IsTrue(LogEventPropertyValue value)
42+
public static bool IsTrue(LogEventPropertyValue? value)
4243
{
4344
return Boolean(value, out var b) && b;
4445
}
4546

46-
public static bool String(LogEventPropertyValue value, out string str)
47+
public static bool String(LogEventPropertyValue? value, [MaybeNullWhen(false)] out string str)
4748
{
4849
if (value is ScalarValue sv)
4950
{
@@ -70,8 +71,8 @@ public static bool String(LogEventPropertyValue value, out string str)
7071
return false;
7172
}
7273

73-
public static bool Predicate(LogEventPropertyValue value,
74-
out Func<LogEventPropertyValue, LogEventPropertyValue> predicate)
74+
public static bool Predicate(LogEventPropertyValue? value,
75+
[MaybeNullWhen(false)] out Func<LogEventPropertyValue, LogEventPropertyValue> predicate)
7576
{
7677
if (value is ScalarValue sv &&
7778
sv.Value is Func<LogEventPropertyValue, LogEventPropertyValue> pred)

0 commit comments

Comments
 (0)