From 6d5f8ef74667ad0262c30ce501db6c4e625dcef7 Mon Sep 17 00:00:00 2001
From: Alexander Vincent <16097639+f2calv@users.noreply.github.com>
Date: Wed, 3 Mar 2021 05:12:35 +0100
Subject: [PATCH 1/2] add .net standard 2.0 compatibity
---
.../Expressions/Runtime/RuntimeOperators.cs | 1 +
src/Serilog.Expressions/Extensions/Helpers.cs | 42 +++++++++++++++++++
.../Serilog.Expressions.csproj | 2 +-
.../NotNullAttributes.cs | 27 ++++++++++++
4 files changed, 71 insertions(+), 1 deletion(-)
create mode 100644 src/Serilog.Expressions/Extensions/Helpers.cs
create mode 100644 src/Serilog.Expressions/System.Diagnostics.CodeAnalysis/NotNullAttributes.cs
diff --git a/src/Serilog.Expressions/Expressions/Runtime/RuntimeOperators.cs b/src/Serilog.Expressions/Expressions/Runtime/RuntimeOperators.cs
index 580fa2b..788efb3 100644
--- a/src/Serilog.Expressions/Expressions/Runtime/RuntimeOperators.cs
+++ b/src/Serilog.Expressions/Expressions/Runtime/RuntimeOperators.cs
@@ -3,6 +3,7 @@
using System.Linq;
using Serilog.Events;
using Serilog.Expressions.Compilation.Linq;
+using Serilog.Extensions;
// ReSharper disable ForCanBeConvertedToForeach, InvertIf, MemberCanBePrivate.Global, UnusedMember.Global
diff --git a/src/Serilog.Expressions/Extensions/Helpers.cs b/src/Serilog.Expressions/Extensions/Helpers.cs
new file mode 100644
index 0000000..6475234
--- /dev/null
+++ b/src/Serilog.Expressions/Extensions/Helpers.cs
@@ -0,0 +1,42 @@
+// Copyright Serilog Contributors
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+using System;
+
+namespace Serilog.Extensions
+{
+ ///
+ /// Helper methods.
+ ///
+ public static class Helpers
+ {
+#if NETSTANDARD2_0
+ ///
+ /// Backport .NET Standard 2.1 additions to maintain .NET Standard 2.0 compatibility.
+ /// Returns a value indicating whether a specified string occurs within this string, using the specified comparison rules.
+ ///
+ /// input string
+ /// The string to seek.
+ /// Specifies the rule to use in the comparison.
+ ///
+ public static bool Contains(this string source, string value, StringComparison comparisonType)
+ {
+ // See;
+ // https://github.com/dotnet/runtime/issues/22198
+ // https://stackoverflow.com/questions/444798/case-insensitive-containsstring/444818#444818
+ return source?.IndexOf(value, comparisonType) >= 0;
+ }
+#endif
+ }
+}
\ No newline at end of file
diff --git a/src/Serilog.Expressions/Serilog.Expressions.csproj b/src/Serilog.Expressions/Serilog.Expressions.csproj
index 132a9ec..5dfdc9c 100644
--- a/src/Serilog.Expressions/Serilog.Expressions.csproj
+++ b/src/Serilog.Expressions/Serilog.Expressions.csproj
@@ -5,7 +5,7 @@
events, ideal for use with JSON or XML configuration.
1.1.0
Serilog Contributors
- netstandard2.1
+ netstandard2.0;netstandard2.1
true
true
Serilog
diff --git a/src/Serilog.Expressions/System.Diagnostics.CodeAnalysis/NotNullAttributes.cs b/src/Serilog.Expressions/System.Diagnostics.CodeAnalysis/NotNullAttributes.cs
new file mode 100644
index 0000000..0654fc3
--- /dev/null
+++ b/src/Serilog.Expressions/System.Diagnostics.CodeAnalysis/NotNullAttributes.cs
@@ -0,0 +1,27 @@
+#if NETSTANDARD2_0
+//https://medium.com/@SergioPedri/enabling-and-using-c-9-features-on-older-and-unsupported-runtimes-ce384d8debb
+namespace System.Diagnostics.CodeAnalysis
+{
+ /// Specifies that an output will not be null even if the corresponding type allows it. Specifies that an input argument was not null when the call returns.
+ [AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue, Inherited = false)]
+ internal sealed class NotNullAttribute : Attribute { }
+
+ /// Specifies that when a method returns , the parameter may be null even if the corresponding type disallows it.
+ [AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
+ internal sealed class MaybeNullWhenAttribute : Attribute
+ {
+ /// Initializes the attribute with the specified return value condition.
+ ///
+ /// The return value condition. If the method returns this value, the associated parameter may be null.
+ ///
+ public MaybeNullWhenAttribute(bool returnValue) => ReturnValue = returnValue;
+
+ /// Gets the return value condition.
+ public bool ReturnValue { get; }
+ }
+
+ // NOTE: you can find the full list of attributes in this gist:
+ // https://gist.github.com/Sergio0694/eb988b243dd4a720a66fe369b63e5b08.
+ // Keeping this one shorter so that the Medium embed doesn't take up too much space.
+}
+#endif
\ No newline at end of file
From 9a85d87d8a51aeb43fbf806c3662f0c982122990 Mon Sep 17 00:00:00 2001
From: Alexander Vincent <16097639+f2calv@users.noreply.github.com>
Date: Wed, 3 Mar 2021 06:51:03 +0100
Subject: [PATCH 2/2] implemented feedback
---
.../{Extensions => Expressions}/Helpers.cs | 18 ++++++++++--------
.../Expressions/Runtime/RuntimeOperators.cs | 1 -
.../NotNullAttributes.cs | 11 +++++------
3 files changed, 15 insertions(+), 15 deletions(-)
rename src/Serilog.Expressions/{Extensions => Expressions}/Helpers.cs (84%)
diff --git a/src/Serilog.Expressions/Extensions/Helpers.cs b/src/Serilog.Expressions/Expressions/Helpers.cs
similarity index 84%
rename from src/Serilog.Expressions/Extensions/Helpers.cs
rename to src/Serilog.Expressions/Expressions/Helpers.cs
index 6475234..368f816 100644
--- a/src/Serilog.Expressions/Extensions/Helpers.cs
+++ b/src/Serilog.Expressions/Expressions/Helpers.cs
@@ -12,19 +12,24 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+#if NETSTANDARD2_0
+
using System;
-namespace Serilog.Extensions
+namespace Serilog.Expressions
{
///
/// Helper methods.
///
- public static class Helpers
+ internal static class Helpers
{
-#if NETSTANDARD2_0
///
/// Backport .NET Standard 2.1 additions to maintain .NET Standard 2.0 compatibility.
/// Returns a value indicating whether a specified string occurs within this string, using the specified comparison rules.
+ ///
+ /// From;
+ /// https://github.com/dotnet/runtime/issues/22198
+ /// https://stackoverflow.com/questions/444798/case-insensitive-containsstring/444818#444818
///
/// input string
/// The string to seek.
@@ -32,11 +37,8 @@ public static class Helpers
///
public static bool Contains(this string source, string value, StringComparison comparisonType)
{
- // See;
- // https://github.com/dotnet/runtime/issues/22198
- // https://stackoverflow.com/questions/444798/case-insensitive-containsstring/444818#444818
return source?.IndexOf(value, comparisonType) >= 0;
}
-#endif
}
-}
\ No newline at end of file
+}
+#endif
\ No newline at end of file
diff --git a/src/Serilog.Expressions/Expressions/Runtime/RuntimeOperators.cs b/src/Serilog.Expressions/Expressions/Runtime/RuntimeOperators.cs
index 788efb3..580fa2b 100644
--- a/src/Serilog.Expressions/Expressions/Runtime/RuntimeOperators.cs
+++ b/src/Serilog.Expressions/Expressions/Runtime/RuntimeOperators.cs
@@ -3,7 +3,6 @@
using System.Linq;
using Serilog.Events;
using Serilog.Expressions.Compilation.Linq;
-using Serilog.Extensions;
// ReSharper disable ForCanBeConvertedToForeach, InvertIf, MemberCanBePrivate.Global, UnusedMember.Global
diff --git a/src/Serilog.Expressions/System.Diagnostics.CodeAnalysis/NotNullAttributes.cs b/src/Serilog.Expressions/System.Diagnostics.CodeAnalysis/NotNullAttributes.cs
index 0654fc3..f2b79ba 100644
--- a/src/Serilog.Expressions/System.Diagnostics.CodeAnalysis/NotNullAttributes.cs
+++ b/src/Serilog.Expressions/System.Diagnostics.CodeAnalysis/NotNullAttributes.cs
@@ -1,5 +1,8 @@
-#if NETSTANDARD2_0
-//https://medium.com/@SergioPedri/enabling-and-using-c-9-features-on-older-and-unsupported-runtimes-ce384d8debb
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+#if NETSTANDARD2_0
+//From: https://medium.com/@SergioPedri/enabling-and-using-c-9-features-on-older-and-unsupported-runtimes-ce384d8debb
namespace System.Diagnostics.CodeAnalysis
{
/// Specifies that an output will not be null even if the corresponding type allows it. Specifies that an input argument was not null when the call returns.
@@ -19,9 +22,5 @@ internal sealed class MaybeNullWhenAttribute : Attribute
/// Gets the return value condition.
public bool ReturnValue { get; }
}
-
- // NOTE: you can find the full list of attributes in this gist:
- // https://gist.github.com/Sergio0694/eb988b243dd4a720a66fe369b63e5b08.
- // Keeping this one shorter so that the Medium embed doesn't take up too much space.
}
#endif
\ No newline at end of file