feat: replace reflection-based trigger discovery with source-generated registry#28
Draft
feat: replace reflection-based trigger discovery with source-generated registry#28
Conversation
Co-authored-by: leeoades <2321091+leeoades@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Make libraries AOT and trimmed for better consumption
feat: AOT and trim compatibility for Core and CommandRunner libraries
Feb 22, 2026
…d trigger type registry Co-authored-by: leeoades <2321091+leeoades@users.noreply.github.com>
Copilot
AI
changed the title
feat: AOT and trim compatibility for Core and CommandRunner libraries
feat: replace reflection-based trigger discovery with source-generated registry
Feb 22, 2026
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.
The unused-trigger analysis in
StateMachineAnalysisusedAssembly.GetTypes()andType.GetProperty()at runtime to discover concrete trigger subtypes — blocking full AOT/trim compatibility and requiring[RequiresUnreferencedCode]/[UnconditionalSuppressMessage]suppression annotations.New:
FunctionalStateMachine.Core.GeneratorA Roslyn incremental source generator that discovers trigger type hierarchies at compile time and replaces all runtime reflection.
StateMachine<TState, TTrigger, ...>.Create()calls (both 3-param NoData and 4-param with-data variants)TTrigger, finds all non-abstract concrete derived types via Roslyn symbol APIs[ModuleInitializerAttribute]is unavailable (graceful no-op on netstandard2.0 without polyfills)FunctionalStateMachine.Coreatanalyzers/dotnet/cs— applies automatically to all NuGet consumersGenerated output:
Core library changes
TriggerTypeRegistry(new): staticTTrigger → Type[]registry populated by the generated initializerStateMachineAnalysis:using System.Reflectionremoved entirely;AnalyzeUnusedTriggersreads from the registry and silently skips if not populated;[RequiresUnreferencedCode]/[UnconditionalSuppressMessage]annotations removedGetTriggerTypeNamewas calling.GetType().NameonTypeobjects (returning"RuntimeType"in error messages); now returns the actual type nameAOT impact
IsAotCompatible=true(net8.0+) is now fully clean — zero remaining IL2026/IL2070 suppressions needed.💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.