Skip to content

Commit 6d5f8ef

Browse files
committed
add .net standard 2.0 compatibity
1 parent 8a7a56c commit 6d5f8ef

File tree

4 files changed

+71
-1
lines changed

4 files changed

+71
-1
lines changed

src/Serilog.Expressions/Expressions/Runtime/RuntimeOperators.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Linq;
44
using Serilog.Events;
55
using Serilog.Expressions.Compilation.Linq;
6+
using Serilog.Extensions;
67

78
// ReSharper disable ForCanBeConvertedToForeach, InvertIf, MemberCanBePrivate.Global, UnusedMember.Global
89

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright Serilog Contributors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
using System;
16+
17+
namespace Serilog.Extensions
18+
{
19+
/// <summary>
20+
/// Helper methods.
21+
/// </summary>
22+
public static class Helpers
23+
{
24+
#if NETSTANDARD2_0
25+
/// <summary>
26+
/// Backport .NET Standard 2.1 additions to maintain .NET Standard 2.0 compatibility.
27+
/// Returns a value indicating whether a specified string occurs within this string, using the specified comparison rules.
28+
/// </summary>
29+
/// <param name="source">input string</param>
30+
/// <param name="value">The string to seek.</param>
31+
/// <param name="comparisonType">Specifies the rule to use in the comparison.</param>
32+
/// <returns></returns>
33+
public static bool Contains(this string source, string value, StringComparison comparisonType)
34+
{
35+
// See;
36+
// https://github.com/dotnet/runtime/issues/22198
37+
// https://stackoverflow.com/questions/444798/case-insensitive-containsstring/444818#444818
38+
return source?.IndexOf(value, comparisonType) >= 0;
39+
}
40+
#endif
41+
}
42+
}

src/Serilog.Expressions/Serilog.Expressions.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
events, ideal for use with JSON or XML configuration.</Description>
66
<VersionPrefix>1.1.0</VersionPrefix>
77
<Authors>Serilog Contributors</Authors>
8-
<TargetFramework>netstandard2.1</TargetFramework>
8+
<TargetFrameworks>netstandard2.0;netstandard2.1</TargetFrameworks>
99
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
1010
<GenerateDocumentationFile>true</GenerateDocumentationFile>
1111
<RootNamespace>Serilog</RootNamespace>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#if NETSTANDARD2_0
2+
//https://medium.com/@SergioPedri/enabling-and-using-c-9-features-on-older-and-unsupported-runtimes-ce384d8debb
3+
namespace System.Diagnostics.CodeAnalysis
4+
{
5+
/// <summary>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.</summary>
6+
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue, Inherited = false)]
7+
internal sealed class NotNullAttribute : Attribute { }
8+
9+
/// <summary>Specifies that when a method returns <see cref="ReturnValue"/>, the parameter may be null even if the corresponding type disallows it.</summary>
10+
[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
11+
internal sealed class MaybeNullWhenAttribute : Attribute
12+
{
13+
/// <summary>Initializes the attribute with the specified return value condition.</summary>
14+
/// <param name="returnValue">
15+
/// The return value condition. If the method returns this value, the associated parameter may be null.
16+
/// </param>
17+
public MaybeNullWhenAttribute(bool returnValue) => ReturnValue = returnValue;
18+
19+
/// <summary>Gets the return value condition.</summary>
20+
public bool ReturnValue { get; }
21+
}
22+
23+
// NOTE: you can find the full list of attributes in this gist:
24+
// https://gist.github.com/Sergio0694/eb988b243dd4a720a66fe369b63e5b08.
25+
// Keeping this one shorter so that the Medium embed doesn't take up too much space.
26+
}
27+
#endif

0 commit comments

Comments
 (0)