-
Notifications
You must be signed in to change notification settings - Fork 569
Refactor to clean up CA1851 warnings #1892
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
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.
PR Overview
This PR refactors code to remove CA1851 warnings by replacing multiple enumerations of IEnumerable with a new extension method and removing suppression attributes.
- Introduced the FirstOrDefaultAndMaxOne extension method in EnumerableExtensions.cs
- Removed CA1851 suppression attributes and replaced enumerations with the new extension method in SemanticConstraint.cs and RelationshipTypeConstraint.cs
Reviewed Changes
| File | Description |
|---|---|
| src/DocumentFormat.OpenXml.Framework/EnumerableExtensions.cs | Added extension method to safely return the first (or default) element while ensuring at most one element exists. |
| src/DocumentFormat.OpenXml.Framework/Validation/Semantic/SemanticConstraint.cs | Removed a suppression attribute and refactored part lookup to use LINQ with FirstOrDefaultAndMaxOne. |
| src/DocumentFormat.OpenXml.Framework/Validation/Semantic/RelationshipTypeConstraint.cs | Removed a suppression attribute and refactored relationship lookup to use FirstOrDefaultAndMaxOne. |
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
Comments suppressed due to low confidence (3)
src/DocumentFormat.OpenXml.Framework/EnumerableExtensions.cs:15
- [nitpick] Consider renaming the parameter 'exThrow' to 'exceptionFactory' for improved clarity.
public static T? FirstOrDefaultAndMaxOne<T>(this IEnumerable<T> enumerable, Func<Exception>? exThrow = null)
src/DocumentFormat.OpenXml.Framework/EnumerableExtensions.cs:25
- [nitpick] The exception message may be improved for clarity; consider rephrasing it to better indicate that the enumerable contains more than one element.
throw exThrow?.Invoke() ?? throw new InvalidOperationException("Max of a single item should be in the enumerable");
src/DocumentFormat.OpenXml.Framework/Validation/Semantic/RelationshipTypeConstraint.cs:67
- [nitpick] Consider passing a custom exception factory lambda to FirstOrDefaultAndMaxOne to provide a more context-specific error message.
.FirstOrDefaultAndMaxOne();
Test Results 70 files 70 suites 1h 8m 48s ⏱️ Results for commit 923a052. |
|
See #1899 |
Fixes #1325