Skip to content

Exclude private/protected fields from source generators#41

Closed
MatthewSteeples wants to merge 1 commit into
lofcz:nextfrom
ledgerscope:next
Closed

Exclude private/protected fields from source generators#41
MatthewSteeples wants to merge 1 commit into
lofcz:nextfrom
ledgerscope:next

Conversation

@MatthewSteeples

Copy link
Copy Markdown
Contributor

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.

Copilot AI review requested due to automatic review settings May 9, 2026 13:23

Copilot AI left a comment

Copy link
Copy Markdown

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 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 private and protected members 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.

Comment thread src/FastCloner.SourceGenerator/MemberCollector.cs Outdated
Comment thread src/FastCloner.SourceGenerator/MemberCollector.cs
Comment thread src/FastCloner.Tests/SourceGeneratorEdgeCaseTests.cs

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comment thread src/FastCloner.SourceGenerator/MemberCollector.cs
@lofcz

lofcz commented May 10, 2026

Copy link
Copy Markdown
Owner

@MatthewSteeples thanks for the contribution. I won't be merging this, since FastCloner by default should fully clone private/protected members (within other rules), this already works in the runtime package and source generator should match the behavior. When #42 lands, use [FastClonerVisibility(FastClonerMemberVisibility.PublicOrInternal)] on your types to match the behavior you wanted.

@lofcz lofcz closed this May 10, 2026
@lofcz

lofcz commented May 10, 2026

Copy link
Copy Markdown
Owner

released v3.5.4 with the described pattern.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants