-
-
Notifications
You must be signed in to change notification settings - Fork 365
feat(CssBuilder): add AddStyle method #5272
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 by SourceryThis pull request introduces the AddStyle method to the CssBuilder class, enabling the addition of CSS styles. No diagrams generated as the changes look simple and do not need a visual representation. 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 @ArgoZhang - I've reviewed your changes - here's some feedback:
Overall Comments:
- Minor typo in test assertions: 'widht' should be 'width' in AddStyle_When test method
Here's what I looked at during the review
- 🟡 General issues: 1 issue found
- 🟢 Security: all looks good
- 🟡 Testing: 2 issues found
- 🟡 Complexity: 1 issue found
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| return this; | ||
| } | ||
|
|
||
| /// <summary> |
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.
issue (complexity): Consider simplifying the AddStyle overloads by using a parameter object to reduce the number of methods and centralize the logic.
The multiple AddStyle overloads can be simplified into a more maintainable pattern using a parameter object approach. This reduces complexity while maintaining all functionality:
public record StyleOptions
{
public string Key { get; init; } = "";
public string? Value { get; init; }
public Func<string?>? ValueFactory { get; init; }
public bool? When { get; init; }
public Func<bool>? WhenFactory { get; init; }
}
public CssBuilder AddStyle(StyleOptions options)
{
if (ShouldAddStyle(options))
{
var value = GetStyleValue(options);
if (!string.IsNullOrEmpty(value))
stringBuffer.Add($"{options.Key}: {value};");
}
return this;
}
// Convenience overload for the most common case
public CssBuilder AddStyle(string key, string? value, bool when = true) =>
AddStyle(new StyleOptions { Key = key, Value = value, When = when });
private static bool ShouldAddStyle(StyleOptions options) =>
(options.WhenFactory?.Invoke() ?? options.When ?? true);
private static string? GetStyleValue(StyleOptions options) =>
options.ValueFactory?.Invoke() ?? options.Value;This approach:
- Reduces the number of overloads from 8 to 2
- Makes the API more extensible for future additions
- Maintains all current functionality
- Improves maintainability with centralized logic
- Keeps the simple cases simple while supporting complex scenarios
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #5272 +/- ##
===========================================
- Coverage 100.00% 99.99% -0.01%
===========================================
Files 639 639
Lines 28767 28777 +10
Branches 4085 4091 +6
===========================================
+ Hits 28767 28775 +8
- Partials 0 2 +2 ☔ View full report in Codecov by Sentry. |
add AddStyle method
Summary of the changes (Less than 80 chars)
简单描述你更改了什么, 不超过80个字符;如果有关联 Issue 请在下方填写相关编号
Description
fixes #5271
Regression?
[If yes, specify the version the behavior has regressed from]
[是否影响老版本]
Risk
[Justify the selection above]
Verification
Packaging changes reviewed?
☑️ Self Check before Merge
Summary by Sourcery
New Features:
AddStylemethod to theCssBuilderclass to conditionally add styles based on boolean values or functions.