From dabc87d18526ceb97d7cb7c93cb9f94f14d784f8 Mon Sep 17 00:00:00 2001 From: Archi Date: Sun, 23 Jan 2022 00:29:04 +0100 Subject: [PATCH] Add generic Enum.IsDefined() --- Directory.Build.props | 2 +- ...ticExtensions.cs => StaticExtensions20.cs} | 52 ++------------ JustArchiNET.Madness/StaticExtensions21.cs | 71 +++++++++++++++++++ 3 files changed, 78 insertions(+), 47 deletions(-) rename JustArchiNET.Madness/{StaticExtensions.cs => StaticExtensions20.cs} (83%) create mode 100644 JustArchiNET.Madness/StaticExtensions21.cs diff --git a/Directory.Build.props b/Directory.Build.props index b2eed95..05ac33d 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,6 +1,6 @@ - 3.1.1 + 3.2.0 diff --git a/JustArchiNET.Madness/StaticExtensions.cs b/JustArchiNET.Madness/StaticExtensions20.cs similarity index 83% rename from JustArchiNET.Madness/StaticExtensions.cs rename to JustArchiNET.Madness/StaticExtensions20.cs index 2588991..97538d7 100644 --- a/JustArchiNET.Madness/StaticExtensions.cs +++ b/JustArchiNET.Madness/StaticExtensions20.cs @@ -4,7 +4,7 @@ // \__ \\__ \| __/| | | || (_| || (_| || | | | // |___/|___/ \___||_| |_| \__,_| \__,_||_| |_| // | -// Copyright 2021-2021 Łukasz "JustArchi" Domeradzki +// Copyright 2021-2022 Łukasz "JustArchi" Domeradzki // Contact: JustArchi@JustArchi.net // | // Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,48 +20,21 @@ // limitations under the License. #if !NETSTANDARD2_1_OR_GREATER +using System; using System.Collections.Generic; +using System.IO; using System.Net.WebSockets; using System.Threading; -using JustArchiNET.Madness.Internal; -#endif -using System; -using System.IO; -using System.Security.Cryptography; -using System.Text; using System.Threading.Tasks; using JetBrains.Annotations; using JustArchiNET.Madness.Helpers; -using Microsoft.AspNetCore.Hosting; +using JustArchiNET.Madness.Internal; namespace JustArchiNET.Madness; [MadnessType(EMadnessType.Extension)] [PublicAPI] -public static class StaticExtensions { - [MadnessType(EMadnessType.Implementation)] - public static StringBuilder Append(this StringBuilder stringBuilder, IFormatProvider? provider, string text) { - if (stringBuilder == null) { - throw new ArgumentNullException(nameof(stringBuilder)); - } - - if (text == null) { - throw new ArgumentNullException(nameof(text)); - } - - return stringBuilder.Append(text.ToString(provider)); - } - - [MadnessType(EMadnessType.Implementation)] - public static Task ComputeHashAsync(this HashAlgorithm hashAlgorithm, Stream inputStream) { - if (hashAlgorithm == null) { - throw new ArgumentNullException(nameof(hashAlgorithm)); - } - - return Task.FromResult(hashAlgorithm.ComputeHash(inputStream)); - } - -#if !NETSTANDARD2_1_OR_GREATER +public static class StaticExtensions20 { [MadnessType(EMadnessType.Implementation)] public static IAsyncDisposable ConfigureAwait(this IDisposable source, bool continueOnCapturedContext) { if (source == null) { @@ -70,20 +43,7 @@ public static IAsyncDisposable ConfigureAwait(this IDisposable source, bool cont return new AsyncDisposableWrapper(source, continueOnCapturedContext); } -#endif - - [MadnessType(EMadnessType.Implementation)] - public static IWebHostBuilder ConfigureWebHostDefaults(this IWebHostBuilder builder, Action configure) { - if (configure == null) { - throw new ArgumentNullException(nameof(configure)); - } - - configure(builder); - - return builder; - } -#if !NETSTANDARD2_1_OR_GREATER [MadnessType(EMadnessType.Implementation)] public static bool Contains(this string input, char value) { if (input == null) { @@ -240,5 +200,5 @@ private static ValueTask FakeDisposeAsync(IDisposable? disposable) { return default(ValueTask); } -#endif } +#endif diff --git a/JustArchiNET.Madness/StaticExtensions21.cs b/JustArchiNET.Madness/StaticExtensions21.cs new file mode 100644 index 0000000..eac53a4 --- /dev/null +++ b/JustArchiNET.Madness/StaticExtensions21.cs @@ -0,0 +1,71 @@ +// _ __ __ +// ___ ___ ___ _ __ __| | __ _ | \/ | +// / __|/ __| / _ \| '_ \ / _` | / _` || |\/| | +// \__ \\__ \| __/| | | || (_| || (_| || | | | +// |___/|___/ \___||_| |_| \__,_| \__,_||_| |_| +// | +// Copyright 2021-2022 Łukasz "JustArchi" Domeradzki +// Contact: JustArchi@JustArchi.net +// | +// 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; +using System.IO; +using System.Security.Cryptography; +using System.Text; +using System.Threading.Tasks; +using JetBrains.Annotations; +using JustArchiNET.Madness.Helpers; +using Microsoft.AspNetCore.Hosting; + +namespace JustArchiNET.Madness; + +[MadnessType(EMadnessType.Extension)] +[PublicAPI] +public static class StaticExtensions21 { + [MadnessType(EMadnessType.Implementation)] + public static StringBuilder Append(this StringBuilder stringBuilder, IFormatProvider? provider, string text) { + if (stringBuilder == null) { + throw new ArgumentNullException(nameof(stringBuilder)); + } + + if (text == null) { + throw new ArgumentNullException(nameof(text)); + } + + return stringBuilder.Append(text.ToString(provider)); + } + + [MadnessType(EMadnessType.Implementation)] + public static Task ComputeHashAsync(this HashAlgorithm hashAlgorithm, Stream inputStream) { + if (hashAlgorithm == null) { + throw new ArgumentNullException(nameof(hashAlgorithm)); + } + + return Task.FromResult(hashAlgorithm.ComputeHash(inputStream)); + } + + [MadnessType(EMadnessType.Implementation)] + public static IWebHostBuilder ConfigureWebHostDefaults(this IWebHostBuilder builder, Action configure) { + if (configure == null) { + throw new ArgumentNullException(nameof(configure)); + } + + configure(builder); + + return builder; + } + + [MadnessType(EMadnessType.Implementation)] + public static bool IsDefined(TEnum value) where TEnum : struct, Enum => Enum.IsDefined(value.GetType(), value); +}