Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

some more nullables #1720

Merged
merged 2 commits into from Aug 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Serilog/Context/LogContextEnricher.cs
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#nullable enable
using Serilog.Core;
using Serilog.Events;

Expand Down
1 change: 1 addition & 0 deletions src/Serilog/Core/Filters/DelegateFilter.cs
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#nullable enable
using System;
using Serilog.Events;

Expand Down
4 changes: 3 additions & 1 deletion src/Serilog/Core/IDestructuringPolicy.cs
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#nullable enable
using System.Diagnostics.CodeAnalysis;
using Serilog.Events;

namespace Serilog.Core
Expand All @@ -29,6 +31,6 @@ public interface IDestructuringPolicy
/// <param name="propertyValueFactory">Recursively apply policies to destructure additional values.</param>
/// <param name="result">The destructured value, or null.</param>
/// <returns>True if the value could be destructured under this policy.</returns>
bool TryDestructure(object value, ILogEventPropertyValueFactory propertyValueFactory, out LogEventPropertyValue result);
bool TryDestructure(object value, ILogEventPropertyValueFactory propertyValueFactory, [NotNullWhen(true)] out LogEventPropertyValue? result);
}
}
3 changes: 2 additions & 1 deletion src/Serilog/Core/Pipeline/MessageTemplateCache.cs
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#nullable enable
using System;
using Serilog.Events;

Expand Down Expand Up @@ -52,7 +53,7 @@ public MessageTemplate Parse(string messageTemplate)
#if HASHTABLE
// ReSharper disable once InconsistentlySynchronizedField
// ignored warning because this is by design
var result = (MessageTemplate)_templates[messageTemplate];
var result = (MessageTemplate?)_templates[messageTemplate];
if (result != null)
return result;
#else
Expand Down
4 changes: 3 additions & 1 deletion src/Serilog/Policies/DelegateDestructuringPolicy.cs
Expand Up @@ -12,15 +12,17 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#nullable enable
using System;
using System.Diagnostics.CodeAnalysis;
using Serilog.Core;
using Serilog.Events;

namespace Serilog.Policies
{
class DelegateDestructuringPolicy : IDestructuringPolicy
{
public bool TryDestructure(object value, ILogEventPropertyValueFactory propertyValueFactory, out LogEventPropertyValue result)
public bool TryDestructure(object value, ILogEventPropertyValueFactory propertyValueFactory, [NotNullWhen(true)] out LogEventPropertyValue? result)
{
if (value is Delegate del)
{
Expand Down
4 changes: 3 additions & 1 deletion src/Serilog/Policies/ProjectedDestructuringPolicy.cs
Expand Up @@ -12,7 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#nullable enable
using System;
using System.Diagnostics.CodeAnalysis;
using Serilog.Core;
using Serilog.Events;

Expand All @@ -29,7 +31,7 @@ public ProjectedDestructuringPolicy(Func<Type, bool> canApply, Func<object, obje
_projection = projection ?? throw new ArgumentNullException(nameof(projection));
}

public bool TryDestructure(object value, ILogEventPropertyValueFactory propertyValueFactory, out LogEventPropertyValue result)
public bool TryDestructure(object value, ILogEventPropertyValueFactory propertyValueFactory, [NotNullWhen(true)] out LogEventPropertyValue? result)
{
if (value == null) throw new ArgumentNullException(nameof(value));

Expand Down
Expand Up @@ -12,7 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#nullable enable
using System;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using Serilog.Core;
using Serilog.Events;
Expand All @@ -21,7 +23,7 @@ namespace Serilog.Policies
{
class ReflectionTypesScalarDestructuringPolicy : IDestructuringPolicy
{
public bool TryDestructure(object value, ILogEventPropertyValueFactory propertyValueFactory, out LogEventPropertyValue result)
public bool TryDestructure(object value, ILogEventPropertyValueFactory propertyValueFactory, [NotNullWhen(true)] out LogEventPropertyValue? result)
{
// These types and their subclasses are property-laden and deep;
// most sinks will convert them to strings.
Expand Down
3 changes: 2 additions & 1 deletion test/TestDummies/DummyHardCodedStringDestructuringPolicy.cs
@@ -1,4 +1,5 @@
using System;
using System.Diagnostics.CodeAnalysis;
using Serilog.Core;
using Serilog.Events;

Expand All @@ -13,7 +14,7 @@ public DummyHardCodedStringDestructuringPolicy(string hardCodedString)
_hardCodedString = hardCodedString ?? throw new ArgumentNullException(nameof(hardCodedString));
}

public bool TryDestructure(object value, ILogEventPropertyValueFactory propertyValueFactory, out LogEventPropertyValue result)
public bool TryDestructure(object value, ILogEventPropertyValueFactory propertyValueFactory, [NotNullWhen(true)] out LogEventPropertyValue? result)
{
result = new ScalarValue(_hardCodedString);
return true;
Expand Down