Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Aug 22, 2025

This PR significantly enhances the C# value equality documentation to address critical gaps and technical inaccuracies identified during review, while restructuring code examples for better readability.

Key Improvements

Enhanced Records Documentation

  • Clarified how records correctly implement IEquatable<T> using virtual methods that check runtime types
  • Renamed "Records with Collections" to "Records with members that use reference equality" for broader applicability
  • Improved guidance to cover all reference types except those with value-based equality like string
  • Made solutions more actionable with specific implementation guidance

Corrected Polymorphic Equality Explanation

  • Fixed misleading explanation that suggested explicit interface implementation "forces" equality comparisons
  • Clarified that correct polymorphic behavior comes from proper virtual Equals(object?) override with runtime type checking
  • Emphasized that the key is how object.Equals is implemented, not the interface implementation pattern

Restructured Code Examples

  • Broke up long, monolithic code samples into focused snippets with targeted explanations
  • Added snippet tags with id= syntax to include specific sections: problem demonstration, solution examples, edge cases
  • Each code section now has contextual explanation, making complex implementations easier to understand
  • Separated logical concerns (problem vs solution, different collection types, polymorphic scenarios)

Content and Style Improvements

  • Updated AI usage metadata to "ai-assisted" per documentation guidelines
  • Improved conciseness by removing unnecessary introductory words
  • Enhanced xref usage patterns (only on first reference)
  • Converted bullet points to appropriate prose where needed
  • Streamlined content flow and removed redundant information

The documentation now correctly explains the nuances of value equality in inheritance scenarios and provides clear, digestible examples that demonstrate both problematic patterns and their solutions.

Fixes #45164.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.


Internal previews

📄 File 🔗 Preview link
docs/csharp/programming-guide/statements-expressions-operators/how-to-define-value-equality-for-a-type.md docs/csharp/programming-guide/statements-expressions-operators/how-to-define-value-equality-for-a-type

… and records with collections

Co-authored-by: BillWagner <493969+BillWagner@users.noreply.github.com>
Co-authored-by: BillWagner <493969+BillWagner@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] Improve the documentation of value equality for C# Improve C# value equality documentation for polymorphic scenarios and records with collections Aug 22, 2025
@Copilot Copilot AI requested a review from BillWagner August 22, 2025 18:29
Copilot finished work on behalf of BillWagner August 22, 2025 18:29
Copy link
Member

@BillWagner BillWagner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot this is a good start, but there's a lot to fix and clarify.

…arify polymorphic equality

Co-authored-by: BillWagner <493969+BillWagner@users.noreply.github.com>
@Copilot Copilot AI changed the title Improve C# value equality documentation for polymorphic scenarios and records with collections Improve C# value equality documentation based on technical review feedback Aug 25, 2025
@Copilot Copilot AI requested a review from BillWagner August 25, 2025 18:55
Copilot finished work on behalf of BillWagner August 25, 2025 18:55
Copy link
Member

@BillWagner BillWagner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Closer, but still a lot to do.

Copy link
Member

@BillWagner BillWagner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot I have two more major comments to address.

… samples with snippet tags

Co-authored-by: BillWagner <493969+BillWagner@users.noreply.github.com>
@Copilot Copilot AI changed the title Improve C# value equality documentation based on technical review feedback Improve C# value equality documentation with enhanced content and structured code examples Aug 25, 2025
@Copilot Copilot AI requested a review from BillWagner August 25, 2025 20:38
Copilot finished work on behalf of BillWagner August 25, 2025 20:38
Copy link
Member

@BillWagner BillWagner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is ready for final review.

(I think this article still needs some work, but let's leave that for another day)

@BillWagner BillWagner marked this pull request as ready for review August 25, 2025 20:55
@BillWagner BillWagner requested a review from a team as a code owner August 25, 2025 20:55
@BillWagner BillWagner requested a review from adegeo August 25, 2025 20:55
Copy link
Contributor

@adegeo adegeo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved to unblock with some minor issues to fix.

…readability

Co-authored-by: adegeo <67293991+adegeo@users.noreply.github.com>
Copilot finished work on behalf of adegeo August 26, 2025 15:53
@Copilot Copilot AI requested a review from adegeo August 26, 2025 15:53
@BillWagner BillWagner merged commit 1a268e5 into main Aug 26, 2025
10 checks passed
@BillWagner BillWagner deleted the copilot/fix-45164 branch August 26, 2025 15:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve the documentation of value equality for C#
3 participants