-
-
Notifications
You must be signed in to change notification settings - Fork 362
feat(Table): support interface TItem #6619
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
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideAdds support for interface-style generic types in ObjectExtensions.CreateInstance by early-returning default for interfaces and introduces a unit test to verify this behavior. Class diagram for updated ObjectExtensions.CreateInstance methodclassDiagram
class ObjectExtensions {
+static TItem? CreateInstance<TItem>(bool isAutoInitializeModelProperty = false)
}
ObjectExtensions : CreateInstance<TItem>()
note for ObjectExtensions "Now returns default if TItem is an interface"
Flow diagram for CreateInstance interface support logicflowchart TD
A[Start CreateInstance<TItem>] --> B{Is TItem an interface?}
B -- Yes --> C[Return default]
B -- No --> D[Create instance using Activator.CreateInstance<TItem>]
D --> E{isAutoInitializeModelProperty?}
E -- Yes --> F[Initialize model properties]
E -- No --> G[Return instance]
F --> G[Return instance]
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
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.
Hey there - I've reviewed your changes and they look great!
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location> `src/BootstrapBlazor/Extensions/ObjectExtensions.cs:249` </location>
<code_context>
/// <returns>An instance of the specified type with initialized properties.</returns>
public static TItem? CreateInstance<TItem>(bool isAutoInitializeModelProperty = false)
{
+ if(typeof(TItem).IsInterface)
+ {
+ return default;
+ }
+
</code_context>
<issue_to_address>
Consider handling abstract classes similarly to interfaces.
Abstract classes cannot be instantiated either; consider checking typeof(TItem).IsAbstract to prevent runtime exceptions.
</issue_to_address>
<suggested_fix>
<<<<<<< SEARCH
if(typeof(TItem).IsInterface)
{
return default;
}
=======
if(typeof(TItem).IsInterface || typeof(TItem).IsAbstract)
{
return default;
}
>>>>>>> REPLACE
</suggested_fix>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| if(typeof(TItem).IsInterface) | ||
| { | ||
| return default; | ||
| } |
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.
suggestion (bug_risk): Consider handling abstract classes similarly to interfaces.
Abstract classes cannot be instantiated either; consider checking typeof(TItem).IsAbstract to prevent runtime exceptions.
| if(typeof(TItem).IsInterface) | |
| { | |
| return default; | |
| } | |
| if(typeof(TItem).IsInterface || typeof(TItem).IsAbstract) | |
| { | |
| return default; | |
| } |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6619 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 739 739
Lines 31672 31675 +3
Branches 4458 4459 +1
=========================================
+ Hits 31672 31675 +3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Link issues
fixes #6618
Summary By Copilot
Regression?
Risk
Verification
Packaging changes reviewed?
☑️ Self Check before Merge
Summary by Sourcery
Handle interface types in ObjectExtensions.CreateInstance to return default instead of throwing and add a unit test for this behavior
New Features:
Tests: