dotnet-source-generation-first
Skill4 starsChanged 10 months agoMITView on GitHub
Prefer compile-time source generation over runtime evaluation for repetitive cross-cutting concerns (mapping, logging, regex, etc.).
In this repository67 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- agents-onboardingSkill
- agent-workitem-automationSkill
- architecture-testingSkill
- aspire-integration-testingSkill
- automated-standards-enforcementSkill
- best-practice-introductionSkill
- branching-strategy-and-conventionsSkill
- broken-windowSkill
- change-risk-rollbackSkill
- ci-cd-conformanceSkill
- component-boundary-ownershipSkill
- contract-consistency-validationSkill
- csharp-best-practicesSkill
- deployment-provenanceSkill
- documentation-as-codeSkill
- documentation-scaffoldSkill
- dotnet-bespoke-code-minimisationSkill
- dotnet-best-practicesSkill
- dotnet-domain-primitivesSkill
- dotnet-efcore-practicesSkill
- dotnet-healthchecksSkill
- dotnet-logging-serilogSkill
- dotnet-mapping-standardSkill
- dotnet-open-source-first-governanceSkill
- dotnet-specification-patternSkill
- dotnet-testing-assertionsSkill
- environment-traceabilitySkill
- finishing-a-development-branch-iddSkill
- greenfield-baselineSkill
- impacted-scope-enforcementSkill
- incremental-change-impactSkill
- incremental-deploymentSkill
- innersource-governance-bootstrapSkill
- issue-driven-deliverySkill
- library-extraction-stabilisationSkill
- local-dev-experienceSkill
- markdown-authorSkill
- modern-csharp-coding-standardsSkill
- monorepo-orchestration-setupSkill
- observability-logging-baselineSkill
- pair-programmingSkill
- persona-switchingSkill
- process-skill-routerSkill
- quality-gate-enforcementSkill
- release-tagging-planSkill
- repo-best-practices-bootstrapSkill
- repository-foundation-bootstrapSkill
- requirements-gatheringSkill
- runtime-tooling-validationSkill
- safe-brownfield-refactorSkill
- scoped-colocationSkill
- security-processesSkill
- selective-build-testSkill
- semantic-version-impactSkill
- session-awareSkill
- skills-first-workflowSkill
- static-analysis-securitySkill
- structured-review-workflowSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
9 rules. About 0 are common, 9 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈9
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 11
Prefer compile-time source generation over runtime reflection for repetitive cross-cutting concerns like mapping, serialization, regex, and …
- Distinctive: line 27
Check if a source-generation library exists for the use case (e.g., Mapperly, System.Text.Json source generators, GeneratedRegex)
- Distinctive: line 30
Verify compile-time generation is working (check generated files, no runtime reflection warnings)
- Distinctive: line 42
Prefer source generation over:
- Distinctive: line 55
If a runtime/reflection-based tool is proposed, require explicit justification:
- Distinctive: line 70
Avoid reflection-based discovery for core execution paths.
- Distinctive: line 71
Ensure analyzers/source generators are included and pinned.
- Distinctive: line 81
When evaluating reflection vs source-generated approaches, use this template:
- Distinctive: line 112
Ad-hoc/one-time operations: Not part of hot paths; cost is negligible.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Overview
Prefer compile-time source generation over runtime reflection for repetitive cross-cutting concerns like mapping, serialization, regex, and logging. Source generation provides determinism, compile-time verification, reduced runtime overhead, and better AOT/trimming compatibility.
When to Use
- Introducing or reviewing repetitive cross-cutting mechanisms (mappers, serializers, regex, logging templates)
- Building performance-sensitive systems or services with startup-time concerns
- Targeting AOT compilation or assembly trimming scenarios
- Evaluating mapping or serialization libraries for a new project
- Reviewing PRs that propose reflection-based or runtime codegen approaches
Core Workflow
- Identify the cross-cutting concern (mapping, serialization, regex, logging)
- Check if a source-generation library exists for the use case (e.g., Mapperly, System.Text.Json source generators, GeneratedRegex)
- Evaluate the source-gen library against requirements (API compatibility, feature set, maintainability)
- Implement using the source-generation approach
- Verify compile-time generation is working (check generated files, no runtime reflection warnings)
- Benchmark if performance is critical (use the minimal benchmark template in Load: advanced)
Core
When to use
- Introducing or reviewing repetitive cross-cutting mechanisms (mappers, serializers, regex, logging templates).
- Performance-sensitive systems, services with startup-time concerns, or AOT/trimming constraints.
Defaults (strong preference)
- Prefer source generation over:
- reflection-based scanning,
- runtime expression compilation,
- dynamic invocation for repetitive tasks.
Rationale
- Determinism and compile-time verification.
- Reduced runtime overhead and improved diagnosability.
- Better compatibility with AOT/trimming scenarios.
Review rules
- If a runtime/reflection-based tool is proposed, require explicit justification:
- functional necessity,
- measurable benefits,
- absence of acceptable OSS source-gen alternatives.
Load: examples
- Mapping: prefer a source-generated mapper (e.g., Mapperly-style approach).
- Regex: use compile-time generated regex for hot paths.
- Logging: prefer compile-time friendly patterns (e.g., message template generators where appropriate).
Load: advanced
AOT/trimming checklist
- Avoid reflection-based discovery for core execution paths.
- Ensure analyzers/source generators are included and pinned.
- Validate publish trimming warnings and address them as part of release readiness.
Benchmarking guidance
- Benchmark representative payload sizes and typical request flows.
- Focus on startup time, allocations, and throughput for mapping/serialization-heavy systems.
Minimal benchmark template
When evaluating reflection vs source-generated approaches, use this template:
[MemoryDiagnoser]
public class MappingBenchmark
{
private MySourceEntity _source = default!;
private Mapper _mapper = default!;
[GlobalSetup]
public void Setup() => _mapper = new Mapper();
[Benchmark]
public MyTargetDto Reflection_MapViaReflection() => MapViaReflection(_source);
[Benchmark]
public MyTargetDto SourceGenerated_MapViaSourceGen() => _mapper.Map(_source);
}Focus areas:
- Startup time (cold startup with reflection vs AOT-friendly source gen)
- Allocations per operation
- Throughput (operations/sec) for hot paths
- Comparison baseline: measure reflection first, then source-gen
Acceptable exceptions to source-generation-first
Reflection/runtime codegen may be used when:
- Ad-hoc/one-time operations: Not part of hot paths; cost is negligible.
- Example: Loading configuration at startup (once per app lifetime)
- Justification: Overhead is paid once, not per-request
- Highly dynamic scenarios: Type information unavailable at compile-time.
- Example: Plugin systems where types loaded at runtime from external assemblies
- Justification: No source-gen alternative exists; runtime introspection necessary
- Backwards compatibility constraints: Source-gen requires breaking API changes.
- Example: Maintaining legacy API surface while migrating to source-gen
- Justification: Breaking change risk outweighs performance benefit; schedule migration
- Prototype/experimental phases: Validation before investing in source-gen.
- Example: Proof-of-concept that reflection will later be replaced
- Justification: Speed of iteration > performance; document migration plan
Required for exceptions:
- Explicit PR justification
- Clear scope boundary (not used in hot paths)
- Migration path documented (if temporary)
Load: enforcement
- Any PR adding reflection-based mapping or runtime codegen must include:
- a justification,
- a benchmark or measurable rationale,
- confirmation that no suitable OSS source-gen alternative exists.
Red Flags - STOP
These statements indicate source generation bypass:
| Thought | Reality |
| "Reflection is more flexible" | Source gen handles most cases; flexibility rarely needed |
| "Startup cost doesn't matter" | AOT/trimming require source gen; plan for it early |
| "We'll optimize later" | Retrofitting source gen is expensive; start with it |
| "No source-gen library exists" | Check thoroughly; ecosystem is rapidly growing |
| "It's just a few operations" | Hot paths compound; measure before dismissing |
| "Dynamic types require reflection" | True for plugins; false for most business code |
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

