-
-
Notifications
You must be signed in to change notification settings - Fork 6
Add support for nullable return types in ReactiveCommand #345
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Introduces new unit tests and verified source for ReactiveCommand methods with nullable parameter and return types. Updates generator logic to handle nullable types correctly. Adds usage of nested classes with nullable types in test and example view models, and updates project references accordingly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds support for nullable parameter and return types in ReactiveCommand source generation by updating the generator to preserve nullability annotations when extracting type information.
Key Changes
- Modified
ReactiveCommandGenerator.Execute.csto useGetFullyQualifiedNameWithNullabilityAnnotations()instead ofToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)for method parameters, ensuring nullable type annotations (?) are preserved - Added comprehensive test coverage with a new unit test
FromReactiveCommandWithNullableTypeAndNullableReturnTypeand example implementations in test view models - Added project reference to support the new nested test classes
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| ReactiveCommandGenerator.Execute.cs | Updated parameter type extraction logic to preserve nullability annotations and removed unused import |
| TestViewModel.cs | Added example usage of ReactiveCommand with nullable parameter and return types across different namespaces |
| ReactiveUI.SourceGenerators.Execute.csproj | Added project reference to Nested3 test project |
| Class1.cs (Nested3) | Added example ReactiveCommand implementation with nullable types and constructor that exercises the generated command |
| ReactiveCMDGeneratorTests.cs | Added unit test to verify nullable type support in ReactiveCommand generation |
| ReactiveCommandAttribute.g.verified.cs | Verified generated attribute code matches expected output |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/ReactiveUI.SourceGenerators.Roslyn/ReactiveCommand/ReactiveCommandGenerator.Execute.cs
Outdated
Show resolved
Hide resolved
src/ReactiveUI.SourceGenerators.Roslyn/ReactiveCommand/ReactiveCommandGenerator.Execute.cs
Outdated
Show resolved
Hide resolved
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #345 +/- ##
==========================================
- Coverage 40.16% 40.12% -0.04%
==========================================
Files 61 61
Lines 3466 3469 +3
Branches 398 399 +1
==========================================
Hits 1392 1392
- Misses 1964 1967 +3
Partials 110 110 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Renamed 'methodReturnType' and 'methodParametersstring' to 'argumentType' and 'argumentTypeString' for improved clarity and consistency in naming related to method argument types.
Eliminated the unused variable 'c' of type Class1 from the TestViewModel constructor to clean up the code.
…hub.com/reactiveui/ReactiveUI.SourceGenerators into FixForNullableReturnTypeReactiveCommand
Replaces LINQ ToArray with a range operator in GenerateParentClassDeclarations for improved clarity. Also removes an unused using directive from ReactiveCommandGenerator.cs.
What kind of change does this PR introduce?
Closes #317
What is the current behavior?
#317
What is the new behavior?
Introduces new unit tests and verified source for ReactiveCommand methods with nullable parameter and return types. Updates generator logic to handle nullable types correctly. Adds usage of nested classes with nullable types in test and example view models, and updates project references accordingly.
What might this PR break?
Existing commands are generated with non-null return types.
Please check if the PR fulfills these requirements
Other information: