Summary
Ship a guard behavior: a predicate over the invocation that either returns an exception or calls next. Use it for validation, null checks, and authorization, without DataAnnotations and without an expression language.
API
Construct the behavior with Func<IMethodInvocation, Exception?>. A null result calls next. A non-null exception fails the invocation, and next is not called.
Behavior
- The predicate does not call
next.
- For a synchronous member, the exception is returned through
CreateExceptionReturn, so the stunt throws it on the caller thread.
- For a
Task or ValueTask member, fail before producing the target's awaitable: the returned awaitable is faulted with the predicate's exception.
Acceptance
- A predicate that returns
ArgumentNullException runs the target zero times, and the caller observes that exception.
- A predicate that returns null runs the target once.


Summary
Ship a guard behavior: a predicate over the invocation that either returns an exception or calls
next. Use it for validation, null checks, and authorization, without DataAnnotations and without an expression language.API
Construct the behavior with
Func<IMethodInvocation, Exception?>. A null result callsnext. A non-null exception fails the invocation, andnextis not called.Behavior
next.CreateExceptionReturn, so the stunt throws it on the caller thread.TaskorValueTaskmember, fail before producing the target's awaitable: the returned awaitable is faulted with the predicate's exception.Acceptance
ArgumentNullExceptionruns the target zero times, and the caller observes that exception.