Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Update docs for CompareExchange\<T> #11422

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Update docs for CompareExchange\<T> #11422

wants to merge 2 commits into from

Conversation

gewarren
Copy link
Contributor

@gewarren gewarren commented Jun 9, 2025

Fixes #11419.

Copy link

@Copilot Copilot AI left a 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 updates the XML documentation for the CompareExchange methods by revising type parameter descriptions and summary texts. Key changes include:

  • Removing the explicit reference type constraint from the type parameter T.
  • Updating summary tags to use consistently.
  • Reformulating the remarks section to streamline the note about method overload preference.
Comments suppressed due to low confidence (2)

xml/System.Threading/Interlocked.xml:1344

  • The removal of the explicit reference type constraint on T may be intentional; consider adding a brief note explaining this change to clarify the updated usage.
<typeparam name="T">The type to be used for <paramref name="location1" />, <paramref name="value" />, and <paramref name="comparand" />.</typeparam>

xml/System.Threading/Interlocked.xml:2380

  • [nitpick] Consider retaining the [!NOTE] markup format for this note to maintain consistency with other documentation sections, if that aligns with the project's style guidelines.
This method overload is preferable to the <xref:System.Threading.Interlocked.Exchange%28System.Object%40%2CSystem.Object%29> method overload, because the latter requires late-bound access to the destination object.

@gewarren gewarren requested review from a team and BillWagner June 30, 2025 08:33
@@ -1341,22 +1341,21 @@ If `comparand` and the object in `location1` are equal by reference, then `value
<Parameter Name="comparand" Type="T" Index="2" FrameworkAlternate="dotnet-uwp-10.0;net-10.0;net-5.0;net-6.0;net-7.0;net-8.0;net-9.0;netcore-1.0;netcore-1.1;netcore-2.0;netcore-2.1;netcore-2.2;netcore-3.0;netcore-3.1;netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1;netstandard-1.0;netstandard-1.1;netstandard-1.2;netstandard-1.3;netstandard-1.4;netstandard-1.6;netstandard-2.0;netstandard-2.1" />
</Parameters>
<Docs>
<typeparam name="T">The type to be used for <paramref name="location1" />, <paramref name="value" />, and <paramref name="comparand" />. This type must be a reference type.</typeparam>
Copy link
Member

Choose a reason for hiding this comment

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

This doc update applies to .NET 9+ only. Do we want to capture that?

Copy link
Member

Choose a reason for hiding this comment

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

Maybe by adding NotSupportedException to the list of exceptions this might throw. It can say that on .NET 9 and later, the T is allowed to be types other than reference types, but it will throw if the T isn't supported, in particular for types that aren't reference, primitive, or enum types.


> [!NOTE]
> This method overload is preferable to the <xref:System.Threading.Interlocked.CompareExchange%28System.Object%40%2CSystem.Object%2CSystem.Object%29> method overload, because the latter requires the destination object to be accessed late-bound.
> This method overload is preferable to the <xref:System.Threading.Interlocked.CompareExchange%28System.Object%40%2CSystem.Object%2CSystem.Object%29> method overload, because the latter requires the destination object to be accessed late-bound.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
> This method overload is preferable to the <xref:System.Threading.Interlocked.CompareExchange%28System.Object%40%2CSystem.Object%2CSystem.Object%29> method overload, because the latter requires the destination object to be accessed late-bound.

This is not correct. There is no late-bound access in any of these overloads


> [!NOTE]
> This method overload is preferable to the <xref:System.Threading.Interlocked.Exchange%28System.Object%40%2CSystem.Object%29> method overload, because the latter requires late-bound access to the destination object .
This method overload is preferable to the <xref:System.Threading.Interlocked.Exchange%28System.Object%40%2CSystem.Object%29> method overload, because the latter requires late-bound access to the destination object.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
This method overload is preferable to the <xref:System.Threading.Interlocked.Exchange%28System.Object%40%2CSystem.Object%29> method overload, because the latter requires late-bound access to the destination object.

@jkotas
Copy link
Member

jkotas commented Jul 3, 2025

This is a follow for .NET 9 change dotnet/runtime#104558 .

@jkotas jkotas requested a review from stephentoub July 3, 2025 21:55
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.

Summary for CompareExchange<T> should not mention reference types as of .NET 9
3 participants