Skip to content

Commit e10eae6

Browse files
authored
Merge pull request #25 from f2calv/feature/netstandard2comp
Add .NET Standard 2.0 compatibility
2 parents 8a7a56c + 9a85d87 commit e10eae6

File tree

3 files changed

+71
-1
lines changed

3 files changed

+71
-1
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
#if NETSTANDARD2_0
16+
17+
using System;
18+
19+
namespace Serilog.Expressions
20+
{
21+
/// <summary>
22+
/// Helper methods.
23+
/// </summary>
24+
internal static class Helpers
25+
{
26+
/// <summary>
27+
/// Backport .NET Standard 2.1 additions to maintain .NET Standard 2.0 compatibility.
28+
/// Returns a value indicating whether a specified string occurs within this string, using the specified comparison rules.
29+
///
30+
/// From;
31+
/// https://github.com/dotnet/runtime/issues/22198
32+
/// https://stackoverflow.com/questions/444798/case-insensitive-containsstring/444818#444818
33+
/// </summary>
34+
/// <param name="source">input string</param>
35+
/// <param name="value">The string to seek.</param>
36+
/// <param name="comparisonType">Specifies the rule to use in the comparison.</param>
37+
/// <returns></returns>
38+
public static bool Contains(this string source, string value, StringComparison comparisonType)
39+
{
40+
return source?.IndexOf(value, comparisonType) >= 0;
41+
}
42+
}
43+
}
44+
#endif

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: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
#if NETSTANDARD2_0
5+
//From: https://medium.com/@SergioPedri/enabling-and-using-c-9-features-on-older-and-unsupported-runtimes-ce384d8debb
6+
namespace System.Diagnostics.CodeAnalysis
7+
{
8+
/// <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>
9+
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue, Inherited = false)]
10+
internal sealed class NotNullAttribute : Attribute { }
11+
12+
/// <summary>Specifies that when a method returns <see cref="ReturnValue"/>, the parameter may be null even if the corresponding type disallows it.</summary>
13+
[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
14+
internal sealed class MaybeNullWhenAttribute : Attribute
15+
{
16+
/// <summary>Initializes the attribute with the specified return value condition.</summary>
17+
/// <param name="returnValue">
18+
/// The return value condition. If the method returns this value, the associated parameter may be null.
19+
/// </param>
20+
public MaybeNullWhenAttribute(bool returnValue) => ReturnValue = returnValue;
21+
22+
/// <summary>Gets the return value condition.</summary>
23+
public bool ReturnValue { get; }
24+
}
25+
}
26+
#endif

0 commit comments

Comments
 (0)