-
-
Notifications
You must be signed in to change notification settings - Fork 30
Refactor role comparison logic into RolePosition struct #253
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
Move all role position comparison logic from Role to a new RolePosition struct, including comparison operators and methods. Update Role to expose a Position property of type RolePosition and remove IComparable<Role> implementation. Refactor all usages and tests to use RolePosition for ordering and equality checks. Improve code clarity and maintainability by centralizing comparison logic.
|
The documentation preview is available at https://preview.netcord.dev/253. |
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.
Pull request overview
This PR refactors role comparison logic by extracting it from the Role class into a new RolePosition struct. The Role class now exposes a Position property of type RolePosition and no longer implements IComparable<Role>. All comparison operations and tests have been updated to use the new RolePosition type.
Changes:
- Introduced
RolePositionstruct with comparison operators andIComparable<RolePosition>,IEquatable<RolePosition>implementations - Updated
Roleclass to exposePositionproperty of typeRolePositionand renamed the raw position toRawPosition - Updated all role ordering operations to use
OrderByDescending(r => r.Position)instead ofOrderDescending() - Refactored role comparison tests to use
RolePositioncomparisons
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| NetCord/Role.cs | Removed IComparable<Role> implementation from Role, added RolePosition struct with all comparison logic, and exposed Position property |
| Tests/RoleTest/RoleComparison.cs | Updated all test assertions to compare role.Position instead of role directly |
| Tests/NetCord.Test/Commands/NormalCommands.cs | Changed role ordering from OrderDescending() to OrderByDescending(r => r.Position) |
| NetCord/Rest/RestGuild.cs | Updated role comparison logic to use RolePosition for finding highest position and comparisons |
| Documentation/guides/services/CustomModuleBasesAndContexts/CustomModuleBases/CustomCommandModule.cs | Updated role ordering from OrderDescending() to OrderByDescending(r => r.Position) |
Comments suppressed due to low confidence (1)
NetCord/Rest/RestGuild.cs:73
- This foreach loop immediately maps its iteration variable to another variable - consider mapping the sequence explicitly using '.Select(...)'.
foreach (var role in y.GetRoles(this))
{
var comparisonResult = xHighestPosition.CompareTo(role.Position);
if (comparisonResult < 0)
return -1;
result = Math.Min(result, comparisonResult);
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
NetCord/Rest/RestGuild.cs:73
- This foreach loop immediately maps its iteration variable to another variable - consider mapping the sequence explicitly using '.Select(...)'.
foreach (var role in y.GetRoles(this))
{
var comparisonResult = xHighestPosition.CompareTo(role.Position);
if (comparisonResult < 0)
return -1;
result = Math.Min(result, comparisonResult);
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Move all role position comparison logic from Role to a new RolePosition struct, including comparison operators and methods. Update Role to expose a Position property of type RolePosition and remove IComparable implementation. Refactor all usages and tests to use RolePosition for ordering and equality checks. Improve code clarity and maintainability by centralizing comparison logic.