fix: exclude internal and sealed override members from mock generation#338
fix: exclude internal and sealed override members from mock generation#338
Conversation
- Filter out internal and protected internal members from classes (not interfaces) - Keep abstract members even if they are internal/protected internal - Add tests for internal member filtering scenarios Co-authored-by: vbreuss <3438234+vbreuss@users.noreply.github.com>
… chain - Accumulate sealed members from all types in inheritance chain - Add tests for sealed override methods and properties from base classes Co-authored-by: vbreuss <3438234+vbreuss@users.noreply.github.com>
- Add test combining sealed override, internal, and protected internal members Co-authored-by: vbreuss <3438234+vbreuss@users.noreply.github.com>
- Extract ShouldIncludeMember helper method - Use null-coalescing assignment operator for except list initialization - Improve code maintainability while preserving functionality Co-authored-by: vbreuss <3438234+vbreuss@users.noreply.github.com>
|
@copilot When I try to build the So also for the special methods ( |
…verride filtering When filtering sealed override methods, parameter comparison now ignores nullable annotations (? suffix). This fixes the issue where DependencyObject.Equals(object) wouldn't match object.Equals(object?) due to nullability differences, causing sealed methods to not be properly filtered. Co-authored-by: vbreuss <3438234+vbreuss@users.noreply.github.com>
Fixed in commit b9a42df. The issue was that |
…tation
Replace TrimEnd('?') with explicit EndsWith check and Substring to avoid accidentally removing multiple trailing '?' characters from complex generic types.
Co-authored-by: vbreuss <3438234+vbreuss@users.noreply.github.com>
🚀 Benchmark ResultsDetails
|
There was a problem hiding this comment.
Pull request overview
This PR fixes compilation errors in generated mocks when dealing with internal and sealed override members. The root cause was that the source generator was attempting to mock members that cannot be overridden: internal members from external assemblies and sealed override members in the inheritance chain.
Key changes:
- Added source assembly tracking to filter out external internal members (unless abstract or in interfaces)
- Enhanced member filtering to exclude sealed override members from base classes
- Improved method equality comparison to handle nullability differences in parameters (e.g.,
objectvsobject?)
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| Tests/Mockolate.SourceGenerators.Tests/Sources/ForMockTests.cs | Added comprehensive tests for complex inheritance scenarios with sealed and internal members, including special method handling |
| Source/Mockolate.SourceGenerators/MockGeneratorHelpers.cs | Updated to pass source assembly information to MockClass constructors for internal member filtering |
| Source/Mockolate.SourceGenerators/Entities/MockClass.cs | Updated constructor to receive and propagate source assembly information |
| Source/Mockolate.SourceGenerators/Entities/Method.cs | Enhanced equality comparison to ignore nullability annotations when matching methods (e.g., object vs object?) |
| Source/Mockolate.SourceGenerators/Entities/Class.cs | Added internal member filtering logic and source assembly tracking; refactored sealed member exclusion |
|
|
This is addressed in release v0.48.0. |

Original prompt
FlowDocument#337✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.