Skip to content

Commit

Permalink
add EnumPolyfill.IsDefined (#224)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp authored Sep 15, 2024
1 parent 3c74a55 commit 6c72a76
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion apiCount.include.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
**API count: 340**
**API count: 341**
1 change: 1 addition & 0 deletions api_list.include.md
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@

* `String[] GetNames<TEnum>() where TEnum : Enum, ValueType` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.enum.getnames)
* `TEnum[] GetValues<TEnum>() where TEnum : Enum, ValueType` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.enum.getvalues)
* `Boolean IsDefined<TEnum>(TEnum) where TEnum : Enum, ValueType` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.enum.isdefined#system-enum-isdefined-1(-0))
* `TEnum Parse<TEnum>(String) where TEnum : Enum, ValueType` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.enum.parse#system-enum-parse-1(system-string-system-boolean))
* `TEnum Parse<TEnum>(String, Boolean) where TEnum : Enum, ValueType` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.enum.parse#system-enum-parse-1(system-string-system-boolean))
* `TEnum Parse<TEnum>(ReadOnlySpan<Char>) where TEnum : Enum, ValueType` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.enum.parse#system-enum-parse-1(system-readonlyspan((system-char))))
Expand Down
3 changes: 2 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ The package targets `netstandard2.0` and is designed to support the following ru
* `net5.0`, `net6.0`, `net7.0`, `net8.0`, `net9.0`


**API count: 340**<!-- singleLineInclude: apiCount. path: /apiCount.include.md -->
**API count: 341**<!-- singleLineInclude: apiCount. path: /apiCount.include.md -->


**See [Milestones](../../milestones?state=closed) for release notes.**
Expand Down Expand Up @@ -864,6 +864,7 @@ The class `Polyfill` includes the following extension methods:

* `String[] GetNames<TEnum>() where TEnum : Enum, ValueType` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.enum.getnames)
* `TEnum[] GetValues<TEnum>() where TEnum : Enum, ValueType` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.enum.getvalues)
* `Boolean IsDefined<TEnum>(TEnum) where TEnum : Enum, ValueType` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.enum.isdefined#system-enum-isdefined-1(-0))
* `TEnum Parse<TEnum>(String) where TEnum : Enum, ValueType` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.enum.parse#system-enum-parse-1(system-string-system-boolean))
* `TEnum Parse<TEnum>(String, Boolean) where TEnum : Enum, ValueType` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.enum.parse#system-enum-parse-1(system-string-system-boolean))
* `TEnum Parse<TEnum>(ReadOnlySpan<Char>) where TEnum : Enum, ValueType` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.enum.parse#system-enum-parse-1(system-readonlyspan((system-char))))
Expand Down
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<PropertyGroup>
<Version>6.7.0</Version>
<Version>6.8.0</Version>
<AssemblyVersion>1.0.0</AssemblyVersion>
<PackageTags>Polyfill</PackageTags>
<DisableImplicitNamespaceImports>true</DisableImplicitNamespaceImports>
Expand Down
17 changes: 17 additions & 0 deletions src/Polyfill/EnumPolyfill.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// <auto-generated />

using System.Runtime.CompilerServices;

#pragma warning disable

namespace Polyfills;
Expand Down Expand Up @@ -33,6 +36,20 @@ public static TEnum[] GetValues<TEnum>()
#endif
}

/// <summary>Returns a <see cref="bool"/> telling whether a given integral value exists in a specified enumeration.</summary>
/// <typeparam name="TEnum">The type of the enumeration.</typeparam>
/// <param name="value">The value in <typeparamref name="TEnum"/>.</param>
/// <returns><see langword="true"/> if a given integral value exists in a specified enumeration; <see langword="false"/>, otherwise.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[Link("https://learn.microsoft.com/en-us/dotnet/api/system.enum.isdefined#system-enum-isdefined-1(-0)")]
public static bool IsDefined<TEnum> (TEnum value)
where TEnum : struct, Enum =>
#if NET5_0_OR_GREATER
Enum.IsDefined<TEnum>(value);
#else
Enum.IsDefined(typeof(TEnum), value);
#endif

/// <summary>
/// Retrieves an array of the names of the constants in a specified enumeration type.
/// </summary>
Expand Down

0 comments on commit 6c72a76

Please sign in to comment.