Exclude private/protected fields from source generators#41
Exclude private/protected fields from source generators#41MatthewSteeples wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the FastCloner source generator to avoid generating clone code that would not compile when a clonable type contains non-accessible fields (private/protected), and adds regression tests covering those edge cases.
Changes:
- Exclude
privateandprotectedmembers from source-generator member collection to prevent invalid generated assignments. - Add source-generator edge case tests verifying private/protected fields are skipped (and thus remain default on the clone).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/FastCloner.SourceGenerator/MemberCollector.cs | Skips private/protected members during member collection for generated clone code. |
| src/FastCloner.Tests/SourceGeneratorEdgeCaseTests.cs | Adds tests ensuring private/protected fields do not participate in source-generated cloning. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@MatthewSteeples thanks for the contribution. I won't be merging this, since FastCloner by default should fully clone |
|
released v3.5.4 with the described pattern. |
Private and Protected fields can't be set from extension methods so the current implementation will fail to compile if your class contains either of these.
This fix excludes them from the source generation.