From 65868e38eda92bc46b680f429af14f4b4388b4ba Mon Sep 17 00:00:00 2001 From: Aaron Robinson Date: Mon, 17 Jun 2024 21:00:03 -0700 Subject: [PATCH 1/5] Update InlineArrayAttribute.xml Add note about behavior of Equals() and GetHashCode() when InlineArrayAttribute is applied to a ValueType. --- .../InlineArrayAttribute.xml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/xml/System.Runtime.CompilerServices/InlineArrayAttribute.xml b/xml/System.Runtime.CompilerServices/InlineArrayAttribute.xml index 78df6f99eeb..c7eecb5ccbd 100644 --- a/xml/System.Runtime.CompilerServices/InlineArrayAttribute.xml +++ b/xml/System.Runtime.CompilerServices/InlineArrayAttribute.xml @@ -26,7 +26,17 @@ Indicates that the instance's storage is sequentially replicated times. - This attribute can be used to annotate a type with a single field. The runtime replicates that field in the actual type layout as many times as is specified. + + type with a single field. The runtime replicates that field in the actual type layout as many times as is specified. + +The default implementations of `Equals()` and `GetHashCode()` for types marked with this attribute will throw . Users are required to override both and if they will be used. + + ]]> + The following example shows how to declare an inline array type with eight values. [InlineArray(8)] From 7a63c2abb7d78a7023270abe27e6648dda6beb2e Mon Sep 17 00:00:00 2001 From: Aaron Robinson Date: Tue, 18 Jun 2024 08:50:09 -0700 Subject: [PATCH 2/5] Update InlineArrayAttribute.xml Fix xref tag. --- xml/System.Runtime.CompilerServices/InlineArrayAttribute.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xml/System.Runtime.CompilerServices/InlineArrayAttribute.xml b/xml/System.Runtime.CompilerServices/InlineArrayAttribute.xml index c7eecb5ccbd..e48c0f2e89a 100644 --- a/xml/System.Runtime.CompilerServices/InlineArrayAttribute.xml +++ b/xml/System.Runtime.CompilerServices/InlineArrayAttribute.xml @@ -33,7 +33,7 @@ This attribute can be used to annotate a type with a single field. The runtime replicates that field in the actual type layout as many times as is specified. -The default implementations of `Equals()` and `GetHashCode()` for types marked with this attribute will throw . Users are required to override both and if they will be used. +The default implementations of `Equals()` and `GetHashCode()` for types marked with this attribute will throw . Users are required to override both and if they will be used. ]]> From 74f09110ebfc90bbdb3e3a46eb6bfb49d29854a7 Mon Sep 17 00:00:00 2001 From: Aaron R Robinson Date: Thu, 20 Jun 2024 10:53:39 -0700 Subject: [PATCH 3/5] Additional locations --- .../InlineArrayAttribute.xml | 3 ++- xml/System/ValueType.xml | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/xml/System.Runtime.CompilerServices/InlineArrayAttribute.xml b/xml/System.Runtime.CompilerServices/InlineArrayAttribute.xml index e48c0f2e89a..f26084570b6 100644 --- a/xml/System.Runtime.CompilerServices/InlineArrayAttribute.xml +++ b/xml/System.Runtime.CompilerServices/InlineArrayAttribute.xml @@ -33,7 +33,8 @@ This attribute can be used to annotate a type with a single field. The runtime replicates that field in the actual type layout as many times as is specified. -The default implementations of `Equals()` and `GetHashCode()` for types marked with this attribute will throw . Users are required to override both and if they will be used. +> [!IMPORTANT] +> The default implementations of `Equals()` and `GetHashCode()` for types marked with this attribute will throw . Users are required to override both and if they will be used. ]]> diff --git a/xml/System/ValueType.xml b/xml/System/ValueType.xml index 3d451acb079..59772508d9b 100644 --- a/xml/System/ValueType.xml +++ b/xml/System/ValueType.xml @@ -200,7 +200,9 @@ The m The default implementation calls on each field of the current instance and `obj` and returns `true` if all fields are equal. -> [!TIP] +The default implementation of will throw if is applied to the type. + +> [!IMPORTANT] > Particularly if your value type contains fields that are reference types, you should override the method. This can improve performance and enable you to more closely represent the meaning of equality for the type. ## Notes for the Windows Runtime @@ -274,6 +276,8 @@ The method applies to types derived from For more information, see , and . +The default implementation of will throw if is applied to the type. + ## Notes for the Windows Runtime When you call the method on a Windows Runtime structure, it provides the default behavior for value types that don't override . This is part of the support that .NET provides for the Windows Runtime (see [.NET Support for Windows Store Apps and Windows Runtime](/dotnet/standard/cross-platform/support-for-windows-store-apps-and-windows-runtime)). Windows Runtime structures can't override , even if they're written with C# or Visual Basic, because they can't have methods. (In addition, structures in the Windows Runtime itself don't inherit .) However, they appear to have , , and methods when you use them in your C# or Visual Basic code, and .NET provides the default behavior for these methods. From dba4cb06c8a5f4a1b40c3014a1f6d1581992e9f6 Mon Sep 17 00:00:00 2001 From: Aaron Robinson Date: Thu, 20 Jun 2024 11:50:43 -0700 Subject: [PATCH 4/5] Apply suggestions from code review Co-authored-by: Genevieve Warren <24882762+gewarren@users.noreply.github.com> --- xml/System.Runtime.CompilerServices/InlineArrayAttribute.xml | 4 ++-- xml/System/ValueType.xml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/xml/System.Runtime.CompilerServices/InlineArrayAttribute.xml b/xml/System.Runtime.CompilerServices/InlineArrayAttribute.xml index f26084570b6..78002503fdf 100644 --- a/xml/System.Runtime.CompilerServices/InlineArrayAttribute.xml +++ b/xml/System.Runtime.CompilerServices/InlineArrayAttribute.xml @@ -31,10 +31,10 @@ ## Remarks -This attribute can be used to annotate a type with a single field. The runtime replicates that field in the actual type layout as many times as is specified. +This attribute can be used to annotate a `struct` type with a single field. The runtime replicates that field in the actual type layout as many times as is specified. > [!IMPORTANT] -> The default implementations of `Equals()` and `GetHashCode()` for types marked with this attribute will throw . Users are required to override both and if they will be used. +> The default implementations of `Equals()` and `GetHashCode()` for types marked with this attribute throw . You must override both and if they will be used. ]]> diff --git a/xml/System/ValueType.xml b/xml/System/ValueType.xml index 59772508d9b..712496ce434 100644 --- a/xml/System/ValueType.xml +++ b/xml/System/ValueType.xml @@ -200,7 +200,7 @@ The m The default implementation calls on each field of the current instance and `obj` and returns `true` if all fields are equal. -The default implementation of will throw if is applied to the type. +The default implementation of throws if is applied to the type. > [!IMPORTANT] > Particularly if your value type contains fields that are reference types, you should override the method. This can improve performance and enable you to more closely represent the meaning of equality for the type. @@ -276,7 +276,7 @@ The method applies to types derived from For more information, see , and . -The default implementation of will throw if is applied to the type. +The default implementation of throws if is applied to the type. ## Notes for the Windows Runtime From 90545989fa84f1754b67906d282bb119eb9098de Mon Sep 17 00:00:00 2001 From: Aaron Robinson Date: Thu, 20 Jun 2024 12:27:57 -0700 Subject: [PATCH 5/5] Apply suggestions from code review --- xml/System.Runtime.CompilerServices/InlineArrayAttribute.xml | 2 +- xml/System/ValueType.xml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/xml/System.Runtime.CompilerServices/InlineArrayAttribute.xml b/xml/System.Runtime.CompilerServices/InlineArrayAttribute.xml index 78002503fdf..27ed5cb955d 100644 --- a/xml/System.Runtime.CompilerServices/InlineArrayAttribute.xml +++ b/xml/System.Runtime.CompilerServices/InlineArrayAttribute.xml @@ -34,7 +34,7 @@ This attribute can be used to annotate a `struct` type with a single field. The runtime replicates that field in the actual type layout as many times as is specified. > [!IMPORTANT] -> The default implementations of `Equals()` and `GetHashCode()` for types marked with this attribute throw . You must override both and if they will be used. +> .NET 9 and later, the default implementations of `Equals()` and `GetHashCode()` for types marked with this attribute throw . You must override both and if they will be used. ]]> diff --git a/xml/System/ValueType.xml b/xml/System/ValueType.xml index 712496ce434..3e3df37fd1a 100644 --- a/xml/System/ValueType.xml +++ b/xml/System/ValueType.xml @@ -200,7 +200,7 @@ The m The default implementation calls on each field of the current instance and `obj` and returns `true` if all fields are equal. -The default implementation of throws if is applied to the type. +.NET 9 and later, the default implementation of throws if is applied to the type. > [!IMPORTANT] > Particularly if your value type contains fields that are reference types, you should override the method. This can improve performance and enable you to more closely represent the meaning of equality for the type. @@ -276,7 +276,7 @@ The method applies to types derived from For more information, see , and . -The default implementation of throws if is applied to the type. +.NET 9 and later, the default implementation of throws if is applied to the type. ## Notes for the Windows Runtime