Feature/482 enum guard is defined - #1210
Open
szv wants to merge 2 commits into
Open
Conversation
added 2 commits
August 16, 2026 12:42
Introduce Guard.IsDefined<TEnum> for efficient enum value checks using cached sets. Add EnumCache<TEnum> and ThrowHelper for fast lookups and detailed exceptions. Update csproj to refine package references and add System.Collections.Immutable for .NET Standard.
Added Test_Guard.Enum.cs. Updated AssemblyInfo.cs with InternalsVisibleTo for unit tests. Introduced Test_Guard.Enum.cs with unit tests for EnumCache and Guard.IsDefined, including a new file-scoped TestEnum.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #482
PR Summary
Adds Guard.IsDefined to validate that an enum value corresponds to a declared member.
Alternative Approach
An alternative would be an enum source generator that detects enum types used with Guard.IsDefined and generates specialized membership checks, such as switch-based implementations. The generated code could avoid the runtime Enum.GetValues initialization, frozen-set allocation, hashing, and the internal use of Enum.IsDefined, potentially improving startup and lookup performance.
PR Checklist
componentGuard method