Add IncludeSubtypes to enable subtype cloning for non-abstract classes#44
Add IncludeSubtypes to enable subtype cloning for non-abstract classes#44MizardX wants to merge 3 commits into
Conversation
Introduce IncludeSubtypes property to FastClonerClonableAttribute, allowing non-abstract base classes to opt into runtime subtype dispatch for FastDeepClone. Update code generation and type modeling to support this feature. Add documentation and tests to demonstrate and verify the new behavior.
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds opt-in runtime subtype dispatch for non-abstract base classes via a new IncludeSubtypes flag on [FastClonerClonable], and validates the behavior with new tests and documentation.
Changes:
- Introduces
FastClonerClonableAttribute.IncludeSubtypesand threads it through the source generatorTypeModel. - Generates subtype-dispatch cloning code for non-abstract (class) roots when
IncludeSubtypes = true. - Adds tests + README docs demonstrating/validating the new dispatch behavior.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/FastCloner.Tests/AbstractClassTests.cs | Adds test fixtures and new tests covering IncludeSubtypes on concrete bases. |
| src/FastCloner.SourceGenerator/TypeModelFactory.cs | Reads IncludeSubtypes from the attribute and triggers derived-type collection for dispatch. |
| src/FastCloner.SourceGenerator/TypeModel.cs | Adds IncludeSubtypes to the generator’s type model. |
| src/FastCloner.SourceGenerator/ImplicitTypeAnalyzer.cs | Updates TypeModel construction to use named args after adding a new record parameter. |
| src/FastCloner.SourceGenerator/DerivedTypeCollector.cs | Updates TypeModel construction with named args (avoid positional mismatch). |
| src/FastCloner.SourceGenerator/CloneCodeGenerator.cs | Implements generalized subtype dispatcher and uses it for abstract + opted-in concrete base classes. |
| src/FastCloner.SourceGenerator.Shared/FastClonerClonableAttribute.cs | Adds the public IncludeSubtypes attribute property with XML docs. |
| README.md | Documents opt-in subtype dispatch for non-abstract bases with an example. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@MizardX please be transparent about using AI. One simple way is to add a disclaimer to the top of the description. |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.
Comments suppressed due to low confidence (1)
src/FastCloner.SourceGenerator/TypeModelFactory.cs:1
- This enumerates
symbol.GetAttributes()multiple times and relies onToDisplayString()string comparisons, which can add noticeable overhead in large solutions. Consider iterating attributes once and/or resolving attribute symbols viacompilation.GetTypeByMetadataName(...)and comparing withSymbolEqualityComparer.Defaultto avoid repeated allocations.
using System;
|
CI failed because of "Resource not accessible by integration". All builds and test either succeeded or were cancelled. The Github token normally does not have permission to update the status of foreign commits (from PR's). Your current action I tested the changes in this PR in my own project, and it seems to work as expected. The only question is if |
|
bump Is there something that I must change? Is there some part you are unhappy about? |
|
hey, sorry about not replying earlier, I don't particularly like how this works, will need to think it trough. On the public API level and ergonomics . The request is valid but I wonder if there is a clearer way to go about it. |
|
System.Text.Json has |
This was written using mostly AI supervised by me.
Introduce IncludeSubtypes property to FastClonerClonableAttribute, allowing non-abstract base classes to opt into runtime subtype dispatch for FastDeepClone. Update code generation and type modeling to support this feature. Add documentation and tests to demonstrate and verify the new behavior.
Closes #43