From 64175b5185c64c0491846f3c2c95363dcd9b5ab5 Mon Sep 17 00:00:00 2001 From: hrrrrustic Date: Mon, 12 Apr 2021 16:32:20 +0300 Subject: [PATCH 1/3] readonly annotation --- .../System/Runtime/InteropServices/ArrayWithOffset.cs | 10 +++++----- .../ref/System.Runtime.InteropServices.cs | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/ArrayWithOffset.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/ArrayWithOffset.cs index 5c4c319d883aca..2604b48cde538f 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/ArrayWithOffset.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/ArrayWithOffset.cs @@ -44,18 +44,18 @@ public ArrayWithOffset(object? array, int offset) m_count = totalSize - offset; } - public object? GetArray() => m_array; + public readonly object? GetArray() => m_array; - public int GetOffset() => m_offset; + public readonly int GetOffset() => m_offset; - public override int GetHashCode() => m_count + m_offset; + public override readonly int GetHashCode() => m_count + m_offset; - public override bool Equals([NotNullWhen(true)] object? obj) + public override readonly bool Equals([NotNullWhen(true)] object? obj) { return obj is ArrayWithOffset && Equals((ArrayWithOffset)obj); } - public bool Equals(ArrayWithOffset obj) + public readonly bool Equals(ArrayWithOffset obj) { return obj.m_array == m_array && obj.m_offset == m_offset && obj.m_count == m_count; } diff --git a/src/libraries/System.Runtime.InteropServices/ref/System.Runtime.InteropServices.cs b/src/libraries/System.Runtime.InteropServices/ref/System.Runtime.InteropServices.cs index 5fcb17353156e9..1345665abafa33 100644 --- a/src/libraries/System.Runtime.InteropServices/ref/System.Runtime.InteropServices.cs +++ b/src/libraries/System.Runtime.InteropServices/ref/System.Runtime.InteropServices.cs @@ -103,11 +103,11 @@ public partial struct ArrayWithOffset private object _dummy; private int _dummyPrimitive; public ArrayWithOffset(object? array, int offset) { throw null; } - public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } - public bool Equals(System.Runtime.InteropServices.ArrayWithOffset obj) { throw null; } - public object? GetArray() { throw null; } - public override int GetHashCode() { throw null; } - public int GetOffset() { throw null; } + public override readonly bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } + public readonly bool Equals(System.Runtime.InteropServices.ArrayWithOffset obj) { throw null; } + public readonly object? GetArray() { throw null; } + public readonly override int GetHashCode() { throw null; } + public readonly int GetOffset() { throw null; } public static bool operator ==(System.Runtime.InteropServices.ArrayWithOffset a, System.Runtime.InteropServices.ArrayWithOffset b) { throw null; } public static bool operator !=(System.Runtime.InteropServices.ArrayWithOffset a, System.Runtime.InteropServices.ArrayWithOffset b) { throw null; } } From 9d445d1b39157c64c16d80dd53ef6b8e4ba5262f Mon Sep 17 00:00:00 2001 From: Vlad Date: Fri, 30 Apr 2021 00:48:58 +0300 Subject: [PATCH 2/3] mark whole struct as readonly --- .../Runtime/InteropServices/ArrayWithOffset.cs | 12 ++++++------ .../ref/System.Runtime.InteropServices.cs | 16 ++++++++-------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/ArrayWithOffset.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/ArrayWithOffset.cs index 2604b48cde538f..fa0f9c0b28ced9 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/ArrayWithOffset.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/ArrayWithOffset.cs @@ -6,7 +6,7 @@ namespace System.Runtime.InteropServices { - public struct ArrayWithOffset + public readonly struct ArrayWithOffset { private readonly object? m_array; private readonly int m_offset; @@ -44,18 +44,18 @@ public ArrayWithOffset(object? array, int offset) m_count = totalSize - offset; } - public readonly object? GetArray() => m_array; + public object? GetArray() => m_array; - public readonly int GetOffset() => m_offset; + public int GetOffset() => m_offset; - public override readonly int GetHashCode() => m_count + m_offset; + public override int GetHashCode() => m_count + m_offset; - public override readonly bool Equals([NotNullWhen(true)] object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { return obj is ArrayWithOffset && Equals((ArrayWithOffset)obj); } - public readonly bool Equals(ArrayWithOffset obj) + public bool Equals(ArrayWithOffset obj) { return obj.m_array == m_array && obj.m_offset == m_offset && obj.m_count == m_count; } diff --git a/src/libraries/System.Runtime.InteropServices/ref/System.Runtime.InteropServices.cs b/src/libraries/System.Runtime.InteropServices/ref/System.Runtime.InteropServices.cs index 1345665abafa33..0be757ca176127 100644 --- a/src/libraries/System.Runtime.InteropServices/ref/System.Runtime.InteropServices.cs +++ b/src/libraries/System.Runtime.InteropServices/ref/System.Runtime.InteropServices.cs @@ -98,16 +98,16 @@ public sealed partial class AllowReversePInvokeCallsAttribute : System.Attribute { public AllowReversePInvokeCallsAttribute() { } } - public partial struct ArrayWithOffset + public readonly partial struct ArrayWithOffset { - private object _dummy; - private int _dummyPrimitive; + private readonly object _dummy; + private readonly int _dummyPrimitive; public ArrayWithOffset(object? array, int offset) { throw null; } - public override readonly bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } - public readonly bool Equals(System.Runtime.InteropServices.ArrayWithOffset obj) { throw null; } - public readonly object? GetArray() { throw null; } - public readonly override int GetHashCode() { throw null; } - public readonly int GetOffset() { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } + public bool Equals(System.Runtime.InteropServices.ArrayWithOffset obj) { throw null; } + public object? GetArray() { throw null; } + public override int GetHashCode() { throw null; } + public int GetOffset() { throw null; } public static bool operator ==(System.Runtime.InteropServices.ArrayWithOffset a, System.Runtime.InteropServices.ArrayWithOffset b) { throw null; } public static bool operator !=(System.Runtime.InteropServices.ArrayWithOffset a, System.Runtime.InteropServices.ArrayWithOffset b) { throw null; } } From 6f1e6efbead59345f545511d063daa5e0dfaaa5c Mon Sep 17 00:00:00 2001 From: Vlad Date: Fri, 30 Apr 2021 00:49:51 +0300 Subject: [PATCH 3/3] remove space --- .../ref/System.Runtime.InteropServices.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/System.Runtime.InteropServices/ref/System.Runtime.InteropServices.cs b/src/libraries/System.Runtime.InteropServices/ref/System.Runtime.InteropServices.cs index 0be757ca176127..c9b9178c33b3b6 100644 --- a/src/libraries/System.Runtime.InteropServices/ref/System.Runtime.InteropServices.cs +++ b/src/libraries/System.Runtime.InteropServices/ref/System.Runtime.InteropServices.cs @@ -104,7 +104,7 @@ public readonly partial struct ArrayWithOffset private readonly int _dummyPrimitive; public ArrayWithOffset(object? array, int offset) { throw null; } public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } - public bool Equals(System.Runtime.InteropServices.ArrayWithOffset obj) { throw null; } + public bool Equals(System.Runtime.InteropServices.ArrayWithOffset obj) { throw null; } public object? GetArray() { throw null; } public override int GetHashCode() { throw null; } public int GetOffset() { throw null; }