Skip to content

Constrain behavior extension methods to IStunt - #253

Merged
kzu merged 6 commits into
mainfrom
dev/session-changes
Oct 1, 2026
Merged

kzu merged 6 commits into
mainfrom
dev/session-changes

Conversation

@kzu

@kzu kzu commented Sep 30, 2026 •

Copy link
Copy Markdown
Member

Tightens the behavior configuration API so that AddBehavior/InsertBehavior are only
reachable on actual stunts, and brings the tests, scenarios and docs in line with it.

Constrain behavior extension methods to IStunt

AddBehavior/InsertBehavior each had two shapes: an IStunt overload, and an
unconstrained generic overload that unwrapped a delegate target at runtime and threw
ArgumentException when the receiver turned out not to be a stunt.

The duplicated overloads are gone. What remains is the generic form, constrained to
IStunt:

public static TStunt AddBehavior<TStunt>(this TStunt stunt, ...) where TStunt : IStunt

The constraint keeps the API off arbitrary objects, the type parameter preserves the
concrete receiver type so calls still chain, and passing a non-stunt is now a compile
error rather than a runtime throw.

Tests and scenarios

Behaviors can no longer be configured off a bare stunt instance, so the affected tests and
generator scenarios now create the stunt with Stunt.For<T>, configure behaviors on the
returned StuntReference<T>, and materialize it with ToObject().

Documentation

The API overview and the package description still showed behaviors being added directly
on the stunt. Both now show the Stunt.For<T> / ToObject() pattern, and the overview
mentions Stunt.Get for configuring an already created stunt.

Castle support notes

Castle/Unsupported.md was re-evaluated against what the generator actually emits today.
Custom attribute replication and optional parameter defaults are generated and covered by
AttributeTests, so they moved out of the gap list and into the supported table. The
remaining metadata and serialization entries are narrowed to what is genuinely
Castle-specific, and the interface limitation is restated as the inability to tell
identical interface slots apart.

Build

Dropped the unused ThisAssembly package reference from Stunts.CompiledProxy.


Verified with dotnet test src/Stunts.UnitTests — 211 passed, 0 failed.

@kzu kzu added the enhancement New feature or request label Sep 30, 2026
@kzu
kzu enabled auto-merge (rebase) September 30, 2026 22:26
@kzu
kzu disabled auto-merge September 30, 2026 22:28
kzu added 5 commits September 30, 2026 19:29
AddBehavior/InsertBehavior were duplicated as IStunt and unconstrained
generic overloads, with the generic ones unwrapping a delegate target at
runtime and throwing ArgumentException when the receiver was not a stunt.

Keep only the generic overloads and constrain TStunt to IStunt, so the
API is discoverable only on stunts, the receiver type is preserved for
chaining, and misuse is a compile error instead of a runtime throw.
The IStunt constraint means behaviors can no longer be configured off a
bare stunt instance. Update the affected tests and generator scenarios to
create the stunt with Stunt.For<T>, configure behaviors on the returned
StuntReference<T>, and materialize it with ToObject().
The API overview and package description still showed behaviors being
added directly on the stunt. Show Stunt.For<T> with ToObject(), and
mention Stunt.Get for configuring an already created stunt.
Custom attribute replication and optional parameter defaults are now
generated and covered by AttributeTests, so drop them from the gap list
and record them as supported. Narrow the remaining metadata and
serialization entries to what is genuinely Castle-specific, and restate
the interface limitation as the inability to tell identical interface
slots apart.
Nothing in the project consumes the generated ThisAssembly constants.
@kzu
kzu force-pushed the dev/session-changes branch from 4f30509 to deba077 Compare September 30, 2026 22:31
@kzu kzu changed the title Update stunt APIs and related scenarios Constrain behavior extension methods to IStunt Sep 30, 2026
@kzu
kzu enabled auto-merge (rebase) September 30, 2026 22:32
@kzu
kzu merged commit a312612 into main Oct 1, 2026
6 checks passed
@kzu
kzu deleted the dev/session-changes branch October 1, 2026 17:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant