Skip to content

refactor(source-generators): improve type casting and output generation#254

Merged
j-d-ha merged 5 commits into
mainfrom
fix/update-typecast-to-support-default
Dec 17, 2025
Merged

refactor(source-generators): improve type casting and output generation#254
j-d-ha merged 5 commits into
mainfrom
fix/update-typecast-to-support-default

Conversation

@j-d-ha

@j-d-ha j-d-ha commented Dec 17, 2025

Copy link
Copy Markdown
Collaborator

🚀 Pull Request

📋 Summary

This PR refactors the source generator's type casting mechanism and output generation to improve code quality and maintainability. The changes replace the string-based handler signature building approach with a more type-safe generic casting method, and consolidate the generated code structure.

Key improvements:

  • Replaced BuildHandlerSignature method with BuildHandlerCastCall that uses a generic Utilities.Cast<T> helper
  • Changed from explicit type cast strings (e.g., (Func<string>)handler) to default parameter type inference (e.g., Utilities.Cast(handler, string () => throw null!))
  • Consolidated namespace and using statements to top-level in generated output
  • Improved nullable reference type handling throughout generated code
  • Added file-scoped Utilities class to centralize the generic Cast method

✅ Checklist

  • My changes build cleanly
  • I've added/updated relevant tests
  • I've added/updated documentation or README
  • I've followed the coding style for this project
  • I've tested the changes locally (if applicable)

🧪 Related Issues or PRs

N/A


💬 Notes for Reviewers

This is purely a refactoring change with no functional differences. All test snapshots have been updated to reflect the new generated code format. The new casting approach is more maintainable and reduces the complexity of string-based type signature building.

The generic Cast<T> method uses a default parameter pattern to infer the target delegate type, which is cleaner and more type-safe than constructing type strings.

j-d-ha and others added 4 commits December 16, 2025 21:08
…rCastCall

- Removed BuildHandlerSignature method from DelegateInfoExtensions.
- Updated MapHandlerSources to use BuildHandlerCastCall instead.
- Modified signature construction to use Utilities.Cast for handler processing.
…ullable reference types

- Added explicit null-forgiveness operator for Build methods in unit tests.
- Updated LambdaHostOutputGenerator to include additional namespace and utility class in generated output.
- Simplified and refactored code template files by removing duplicate using statements.
- Enhanced handler signature casting with improved clarity in MapHandler template.
- Updated `Version` property in Directory.Build.props to reflect the new prerelease version.
Signed-off-by: Jonas Ha <61319894+j-d-ha@users.noreply.github.com>
@github-actions github-actions Bot added the type: refactor Code refactoring label Dec 17, 2025
…lity

- Added `Utilities.Cast` method to simplify and enhance handler signature casting.
- Updated snapshot file with organized `using` directives and new casting approach.
- Improved accuracy and clarity in generated handler processing logic.
@sonarqubecloud

Copy link
Copy Markdown

@codecov

codecov Bot commented Dec 17, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #254      +/-   ##
==========================================
+ Coverage   88.41%   88.49%   +0.07%     
==========================================
  Files         130      130              
  Lines        3125     3129       +4     
  Branches      344      340       -4     
==========================================
+ Hits         2763     2769       +6     
+ Misses        229      227       -2     
  Partials      133      133              
Files with missing lines Coverage Δ
...rceGenerators/Extensions/DelegateInfoExtensions.cs 100.00% <100.00%> (ø)
...tors/OutputGenerators/LambdaHostOutputGenerator.cs 100.00% <100.00%> (ø)
...ceGenerators/OutputGenerators/MapHandlerSources.cs 97.93% <100.00%> (ø)

... and 2 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b2ae249...120d2c6. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@j-d-ha
j-d-ha merged commit ad77c7f into main Dec 17, 2025
8 checks passed
@j-d-ha
j-d-ha deleted the fix/update-typecast-to-support-default branch December 17, 2025 02:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: refactor Code refactoring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant