Skip to content
This repository has been archived by the owner on Feb 27, 2024. It is now read-only.

Commit

Permalink
Add generic Enum.IsDefined()
Browse files Browse the repository at this point in the history
  • Loading branch information
JustArchi committed Jan 22, 2022
1 parent 2fff9e6 commit dabc87d
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 47 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>3.1.1</Version>
<Version>3.2.0</Version>
</PropertyGroup>

<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// \__ \\__ \| __/| | | || (_| || (_| || | | |
// |___/|___/ \___||_| |_| \__,_| \__,_||_| |_|
// |
// Copyright 2021-2021 Łukasz "JustArchi" Domeradzki
// Copyright 2021-2022 Łukasz "JustArchi" Domeradzki
// Contact: [email protected]
// |
// Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -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<byte[]> 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) {
Expand All @@ -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<IWebHostBuilder> 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) {
Expand Down Expand Up @@ -240,5 +200,5 @@ private static ValueTask FakeDisposeAsync(IDisposable? disposable) {

return default(ValueTask);
}
#endif
}
#endif
71 changes: 71 additions & 0 deletions JustArchiNET.Madness/StaticExtensions21.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// _ __ __
// ___ ___ ___ _ __ __| | __ _ | \/ |
// / __|/ __| / _ \| '_ \ / _` | / _` || |\/| |
// \__ \\__ \| __/| | | || (_| || (_| || | | |
// |___/|___/ \___||_| |_| \__,_| \__,_||_| |_|
// |
// Copyright 2021-2022 Łukasz "JustArchi" Domeradzki
// Contact: [email protected]
// |
// 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<byte[]> 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<IWebHostBuilder> configure) {
if (configure == null) {
throw new ArgumentNullException(nameof(configure));
}

configure(builder);

return builder;
}

[MadnessType(EMadnessType.Implementation)]
public static bool IsDefined<TEnum>(TEnum value) where TEnum : struct, Enum => Enum.IsDefined(value.GetType(), value);
}

0 comments on commit dabc87d

Please sign in to comment.