Skip to content

fix: remove struct constraint from Guard.Against.Expression to support reference types (#339) - #406

Merged
ardalis merged 2 commits into
ardalis:mainfrom
Moha-sami:fix-expression-reference-types
Sep 2, 2026
Merged

fix: remove struct constraint from Guard.Against.Expression to support reference types (#339)#406
ardalis merged 2 commits into
ardalis:mainfrom
Moha-sami:fix-expression-reference-types

Conversation

@Moha-sami

Copy link
Copy Markdown
Contributor

Fixes#339

Summary

Removes the where T : struct constraint from Guard.Against.Expression<T> and Guard.Against.ExpressionAsync<T> so reference types (classes, strings, objects) can also be validated using custom expression predicates.

Details

  • Updated GuardAgainstExpressionExtensions.cs signatures.
  • Added unit tests in GuardAgainstExpression.cs verifying Guard.Against.Expression for reference types.
  • Verified all 959 unit tests pass cleanly.

@sonarqubecloud

Copy link
Copy Markdown

@ardalis
ardalis merged commit f96b823 into ardalis:mainSep 2, 2026
2 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Can we support Expression on refrence type not only struct

2 participants

@Moha-sami@ardalis