diff --git a/src/Serilog.Expressions/Expressions/Helpers.cs b/src/Serilog.Expressions/Expressions/Helpers.cs new file mode 100644 index 0000000..368f816 --- /dev/null +++ b/src/Serilog.Expressions/Expressions/Helpers.cs @@ -0,0 +1,44 @@ +// 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. + +#if NETSTANDARD2_0 + +using System; + +namespace Serilog.Expressions +{ + /// + /// Helper methods. + /// + internal static class Helpers + { + /// + /// 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. + /// Specifies the rule to use in the comparison. + /// + public static bool Contains(this string source, string value, StringComparison comparisonType) + { + 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..f2b79ba --- /dev/null +++ b/src/Serilog.Expressions/System.Diagnostics.CodeAnalysis/NotNullAttributes.cs @@ -0,0 +1,26 @@ +// 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. + [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; } + } +} +#endif \ No newline at end of file