diff --git a/src/libraries/System.Private.CoreLib/src/System/ArraySegment.cs b/src/libraries/System.Private.CoreLib/src/System/ArraySegment.cs
index e62a847e764eb6..80a0b49ccf66c7 100644
--- a/src/libraries/System.Private.CoreLib/src/System/ArraySegment.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/ArraySegment.cs
@@ -308,7 +308,7 @@ public bool MoveNext()
return false;
}
- public T Current
+ public readonly T Current
{
get
{
@@ -327,7 +327,7 @@ void IEnumerator.Reset()
_current = _start - 1;
}
- public void Dispose()
+ public readonly void Dispose()
{
}
}
diff --git a/src/libraries/System.Private.CoreLib/src/System/Buffers/MemoryHandle.cs b/src/libraries/System.Private.CoreLib/src/System/Buffers/MemoryHandle.cs
index 2ac65aa35a1264..c7b2703db2ffab 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Buffers/MemoryHandle.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Buffers/MemoryHandle.cs
@@ -32,7 +32,7 @@ public MemoryHandle(void* pointer, GCHandle handle = default, IPinnable? pinnabl
/// Returns the pointer to memory, where the memory is assumed to be pinned and hence the address won't change.
///
[CLSCompliant(false)]
- public void* Pointer => _pointer;
+ public readonly void* Pointer => _pointer;
///
/// Frees the pinned handle and releases IPinnable.
diff --git a/src/libraries/System.Private.CoreLib/src/System/Collections/DictionaryEntry.cs b/src/libraries/System.Private.CoreLib/src/System/Collections/DictionaryEntry.cs
index 9f2fff9a8d8c16..8a8ef33471c8e2 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Collections/DictionaryEntry.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Collections/DictionaryEntry.cs
@@ -26,13 +26,13 @@ public DictionaryEntry(object key, object? value)
public object Key
{
- get => _key;
+ readonly get => _key;
set => _key = value;
}
public object? Value
{
- get => _value;
+ readonly get => _value;
set => _value = value;
}
@@ -43,7 +43,7 @@ public void Deconstruct(out object key, out object? value)
value = Value;
}
- public override string ToString() =>
+ public override readonly string ToString() =>
KeyValuePair.PairToString(_key, _value);
}
}
diff --git a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/Dictionary.cs b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/Dictionary.cs
index c890bbed83c7ef..8e36360027da09 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/Dictionary.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/Dictionary.cs
@@ -1807,11 +1807,11 @@ public bool MoveNext()
return false;
}
- public KeyValuePair Current => _current;
+ public readonly KeyValuePair Current => _current;
- public void Dispose() { }
+ public readonly void Dispose() { }
- object? IEnumerator.Current
+ readonly object? IEnumerator.Current
{
get
{
@@ -1840,7 +1840,7 @@ void IEnumerator.Reset()
_current = default;
}
- DictionaryEntry IDictionaryEnumerator.Entry
+ readonly DictionaryEntry IDictionaryEnumerator.Entry
{
get
{
@@ -1853,7 +1853,7 @@ DictionaryEntry IDictionaryEnumerator.Entry
}
}
- object IDictionaryEnumerator.Key
+ readonly object IDictionaryEnumerator.Key
{
get
{
@@ -1866,7 +1866,7 @@ object IDictionaryEnumerator.Key
}
}
- object? IDictionaryEnumerator.Value
+ readonly object? IDictionaryEnumerator.Value
{
get
{
@@ -2022,7 +2022,7 @@ internal Enumerator(Dictionary dictionary)
_currentKey = default;
}
- public void Dispose() { }
+ public readonly void Dispose() { }
public bool MoveNext()
{
@@ -2047,9 +2047,9 @@ public bool MoveNext()
return false;
}
- public TKey Current => _currentKey!;
+ public readonly TKey Current => _currentKey!;
- object? IEnumerator.Current
+ readonly object? IEnumerator.Current
{
get
{
@@ -2216,7 +2216,7 @@ internal Enumerator(Dictionary dictionary)
_currentValue = default;
}
- public void Dispose() { }
+ public readonly void Dispose() { }
public bool MoveNext()
{
@@ -2240,9 +2240,9 @@ public bool MoveNext()
return false;
}
- public TValue Current => _currentValue!;
+ public readonly TValue Current => _currentValue!;
- object? IEnumerator.Current
+ readonly object? IEnumerator.Current
{
get
{
diff --git a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/HashSet.cs b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/HashSet.cs
index 6bc713d127f3ca..d129aec88bf441 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/HashSet.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/HashSet.cs
@@ -450,7 +450,7 @@ internal static IAlternateEqualityComparer GetAlternateComparer(H
/// Adds the specified element to a set.
/// The element to add to the set.
/// true if the element is added to the set; false if the element is already present.
- public bool Add(TAlternate item)
+ public readonly bool Add(TAlternate item)
{
HashSet set = Set;
IAlternateEqualityComparer comparer = GetAlternateComparer(set);
@@ -538,7 +538,7 @@ public bool Add(TAlternate item)
/// Removes the specified element from a set.
/// The element to remove.
/// true if the element is successfully found and removed; otherwise, false.
- public bool Remove(TAlternate item)
+ public readonly bool Remove(TAlternate item)
{
HashSet set = Set;
IAlternateEqualityComparer comparer = GetAlternateComparer(set);
@@ -623,7 +623,7 @@ public bool TryGetValue(TAlternate equalValue, [MaybeNullWhen(false)] out T actu
}
/// Finds the item in the set and returns a reference to the found item, or a null reference if not found.
- internal ref readonly T FindValue(TAlternate item)
+ internal readonly ref readonly T FindValue(TAlternate item)
{
HashSet set = Set;
IAlternateEqualityComparer comparer = GetAlternateComparer(set);
@@ -1834,11 +1834,11 @@ public bool MoveNext()
return false;
}
- public T Current => _current;
+ public readonly T Current => _current;
- public void Dispose() { }
+ public readonly void Dispose() { }
- object? IEnumerator.Current
+ readonly object? IEnumerator.Current
{
get
{
diff --git a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/List.cs b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/List.cs
index 119f06ac9fecf5..c10d9638f3930c 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/List.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/List.cs
@@ -1199,7 +1199,7 @@ internal Enumerator(List list)
_current = default;
}
- public void Dispose()
+ public readonly void Dispose()
{
}
@@ -1228,7 +1228,7 @@ private bool MoveNextRare()
return false;
}
- public T Current => _current!;
+ public readonly T Current => _current!;
object? IEnumerator.Current
{
diff --git a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/Queue.cs b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/Queue.cs
index 2c538149ebdb03..1d4995fc4a2843 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/Queue.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/Queue.cs
@@ -490,7 +490,7 @@ public T Current
}
}
- private void ThrowEnumerationNotStartedOrEnded()
+ private readonly void ThrowEnumerationNotStartedOrEnded()
{
Debug.Assert(_index == -1 || _index == -2);
throw new InvalidOperationException(_index == -1 ? SR.InvalidOperation_EnumNotStarted : SR.InvalidOperation_EnumEnded);
diff --git a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/ValueListBuilder.cs b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/ValueListBuilder.cs
index 90c39104efbc8b..b609a114339a05 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/ValueListBuilder.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/ValueListBuilder.cs
@@ -22,7 +22,7 @@ public ValueListBuilder(Span initialSpan)
public int Length
{
- get => _pos;
+ readonly get => _pos;
set
{
Debug.Assert(value >= 0);
@@ -138,12 +138,12 @@ private void AddWithResize(T item)
_pos = pos + 1;
}
- public ReadOnlySpan AsSpan()
+ public readonly ReadOnlySpan AsSpan()
{
return _span.Slice(0, _pos);
}
- public bool TryCopyTo(Span destination, out int itemsWritten)
+ public readonly bool TryCopyTo(Span destination, out int itemsWritten)
{
if (_span.Slice(0, _pos).TryCopyTo(destination))
{
diff --git a/src/libraries/System.Private.CoreLib/src/System/Decimal.DecCalc.cs b/src/libraries/System.Private.CoreLib/src/System/Decimal.DecCalc.cs
index 4b6d93f82fe01f..9cb7bbf0954a08 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Decimal.DecCalc.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Decimal.DecCalc.cs
@@ -61,29 +61,29 @@ private struct DecCalc
private uint High
{
- get => uhi;
+ readonly get => uhi;
set => uhi = value;
}
private uint Low
{
- get => ulo;
+ readonly get => ulo;
set => ulo = value;
}
private uint Mid
{
- get => umid;
+ readonly get => umid;
set => umid = value;
}
- private bool IsNegative => (int)uflags < 0;
+ private readonly bool IsNegative => (int)uflags < 0;
- private int Scale => (byte)(uflags >> ScaleShift);
+ private readonly int Scale => (byte)(uflags >> ScaleShift);
private ulong Low64
{
- get => ulomid;
+ readonly get => ulomid;
set => ulomid = value;
}
@@ -2520,7 +2520,7 @@ public ulong Low64
get => ((ulong)U1 << 32) | U0;
set { U1 = (uint)(value >> 32); U0 = (uint)value; }
#else
- get => ulo64LE;
+ readonly get => ulo64LE;
set => ulo64LE = value;
#endif
}
@@ -2534,7 +2534,7 @@ public ulong High64
get => ((ulong)U2 << 32) | U1;
set { U2 = (uint)(value >> 32); U1 = (uint)value; }
#else
- get => uhigh64LE;
+ readonly get => uhigh64LE;
set => uhigh64LE = value;
#endif
}
@@ -2563,7 +2563,7 @@ public ulong Low64
get => ((ulong)U1 << 32) | U0;
set { U1 = (uint)(value >> 32); U0 = (uint)value; }
#else
- get => ulo64LE;
+ readonly get => ulo64LE;
set => ulo64LE = value;
#endif
}
@@ -2574,7 +2574,7 @@ public ulong High64
get => ((ulong)U3 << 32) | U2;
set { U3 = (uint)(value >> 32); U2 = (uint)value; }
#else
- get => uhigh64LE;
+ readonly get => uhigh64LE;
set => uhigh64LE = value;
#endif
}
@@ -2609,7 +2609,7 @@ public ulong Low64
get => ((ulong)U1 << 32) | U0;
set { U1 = (uint)(value >> 32); U0 = (uint)value; }
#else
- get => ulo64LE;
+ readonly get => ulo64LE;
set => ulo64LE = value;
#endif
}
@@ -2620,7 +2620,7 @@ public ulong Mid64
get => ((ulong)U3 << 32) | U2;
set { U3 = (uint)(value >> 32); U2 = (uint)value; }
#else
- get => umid64LE;
+ readonly get => umid64LE;
set => umid64LE = value;
#endif
}
@@ -2631,7 +2631,7 @@ public ulong High64
get => ((ulong)U5 << 32) | U4;
set { U5 = (uint)(value >> 32); U4 = (uint)value; }
#else
- get => uhigh64LE;
+ readonly get => uhigh64LE;
set => uhigh64LE = value;
#endif
}
diff --git a/src/libraries/System.Private.CoreLib/src/System/Delegate.cs b/src/libraries/System.Private.CoreLib/src/System/Delegate.cs
index 4675761d5d6e2f..20e4a14ec90b4f 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Delegate.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Delegate.cs
@@ -115,7 +115,7 @@ internal InvocationListEnumerator(MulticastDelegate? d)
///
/// Implements the IEnumerator pattern.
///
- public TDelegate Current
+ public readonly TDelegate Current
{
get => _current!;
}
@@ -141,7 +141,7 @@ public bool MoveNext()
///
/// An IEnumerator instance that can be used to iterate through the invocation targets of the delegate.
[EditorBrowsable(EditorBrowsableState.Never)] // Only here to make foreach work
- public System.Delegate.InvocationListEnumerator GetEnumerator() => this;
+ public readonly System.Delegate.InvocationListEnumerator GetEnumerator() => this;
}
public object? DynamicInvoke(params object?[]? args)
diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventPipe.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventPipe.cs
index f89ae1eaae575e..52263d9846f0c6 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventPipe.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventPipe.cs
@@ -98,7 +98,7 @@ internal static void MarshalToNative(EventPipeProviderConfiguration managed, ref
native.m_pFilterData = (char*)Marshal.StringToCoTaskMemUni(managed.FilterData);
}
- internal void Release()
+ internal readonly void Release()
{
if (m_pProviderName != null)
{
diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventPipeMetadataGenerator.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventPipeMetadataGenerator.cs
index ae4e2ad51427f5..4eade6b1b61d0f 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventPipeMetadataGenerator.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventPipeMetadataGenerator.cs
@@ -373,7 +373,7 @@ private static unsafe bool GenerateMetadataForProperty(PropertyAnalysis property
return true;
}
- internal unsafe bool GenerateMetadataV2(byte* pMetadataBlob, ref uint offset, uint blobSize)
+ internal readonly unsafe bool GenerateMetadataV2(byte* pMetadataBlob, ref uint offset, uint blobSize)
{
if (TypeInfo == null)
return false;
@@ -564,7 +564,7 @@ internal static bool GetTypeInfoFromType(Type? type, out TraceLoggingTypeInfo? t
}
}
- internal bool GetMetadataLength(out uint size)
+ internal readonly bool GetMetadataLength(out uint size)
{
size = 0;
@@ -667,7 +667,7 @@ private static TypeCode GetTypeCodeExtended(Type parameterType)
return Type.GetTypeCode(parameterType);
}
- internal bool GetMetadataLengthV2(out uint size)
+ internal readonly bool GetMetadataLengthV2(out uint size)
{
return GetMetadataLengthForNamedTypeV2(ParameterName, TypeInfo, out size);
}
diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs
index d280d33c6e3b5d..fff489d35b7e29 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs
@@ -1253,7 +1253,7 @@ protected internal struct EventData
///
public unsafe IntPtr DataPointer
{
- get => (IntPtr)(void*)m_Ptr;
+ readonly get => (IntPtr)(void*)m_Ptr;
set => m_Ptr = unchecked((ulong)(void*)value);
}
@@ -1262,7 +1262,7 @@ public unsafe IntPtr DataPointer
///
public int Size
{
- get => m_Size;
+ readonly get => m_Size;
set => m_Size = value;
}
@@ -1272,7 +1272,7 @@ public int Size
///
internal int Reserved
{
- get => m_Reserved;
+ readonly get => m_Reserved;
set => m_Reserved = value;
}
@@ -5175,7 +5175,7 @@ public SessionMask(SessionMask m)
public SessionMask(uint mask = 0)
{ m_mask = mask & MASK; }
- public bool IsEqualOrSupersetOf(SessionMask m)
+ public readonly bool IsEqualOrSupersetOf(SessionMask m)
{
return (this.m_mask | m.m_mask) == this.m_mask;
}
@@ -5188,7 +5188,7 @@ public static SessionMask FromId(int perEventSourceSessionId)
return new SessionMask((uint)1 << perEventSourceSessionId);
}
- public ulong ToEventKeywords()
+ public readonly ulong ToEventKeywords()
{
return (ulong)m_mask << SHIFT_SESSION_TO_KEYWORD;
}
@@ -5200,7 +5200,7 @@ public static SessionMask FromEventKeywords(ulong m)
public bool this[int perEventSourceSessionId]
{
- get
+ readonly get
{
Debug.Assert(perEventSourceSessionId < MAX);
return (m_mask & (1 << perEventSourceSessionId)) != 0;
diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/ConcurrentSet.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/ConcurrentSet.cs
index 14c2ad2b3d42e3..c3dc84057bc47a 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/ConcurrentSet.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/ConcurrentSet.cs
@@ -22,7 +22,7 @@ internal struct ConcurrentSet
{
private ItemType[]? items;
- public ItemType? TryGet(KeyType key)
+ public readonly ItemType? TryGet(KeyType key)
{
ItemType? item;
ItemType[]? oldItems = this.items;
diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/EventSourceOptions.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/EventSourceOptions.cs
index ec1fe8d186a5ed..b45586a0e0c3a3 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/EventSourceOptions.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/EventSourceOptions.cs
@@ -29,7 +29,7 @@ public struct EventSourceOptions
///
public EventLevel Level
{
- get => (EventLevel)this.level;
+ readonly get => (EventLevel)this.level;
set
{
this.level = checked((byte)value);
@@ -43,7 +43,7 @@ public EventLevel Level
///
public EventOpcode Opcode
{
- get => (EventOpcode)this.opcode;
+ readonly get => (EventOpcode)this.opcode;
set
{
this.opcode = checked((byte)value);
@@ -51,7 +51,7 @@ public EventOpcode Opcode
}
}
- internal bool IsOpcodeSet => (this.valuesSet & opcodeSet) != 0;
+ internal readonly bool IsOpcodeSet => (this.valuesSet & opcodeSet) != 0;
///
/// Gets or sets the keywords to use for the specified event. If this
@@ -59,7 +59,7 @@ public EventOpcode Opcode
///
public EventKeywords Keywords
{
- get => this.keywords;
+ readonly get => this.keywords;
set
{
this.keywords = value;
@@ -73,7 +73,7 @@ public EventKeywords Keywords
///
public EventTags Tags
{
- get => this.tags;
+ readonly get => this.tags;
set
{
this.tags = value;
@@ -87,7 +87,7 @@ public EventTags Tags
///
public EventActivityOptions ActivityOptions
{
- get => this.activityOptions;
+ readonly get => this.activityOptions;
set
{
this.activityOptions = value;
diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/DateTimeParse.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/DateTimeParse.cs
index bec15897701aa1..2fc354f8343b83 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Globalization/DateTimeParse.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/DateTimeParse.cs
@@ -5370,7 +5370,7 @@ internal ref struct __DTString
internal int Index;
// The length of Value string.
- internal int Length => Value.Length;
+ internal readonly int Length => Value.Length;
// The current character to be looked at.
internal char m_current;
@@ -5397,7 +5397,7 @@ internal __DTString(ReadOnlySpan str, DateTimeFormatInfo dtfi)
m_checkDigitToken = ((dtfi.FormatFlags & DateTimeFormatFlags.UseDigitPrefixInTokens) != 0);
}
- internal CompareInfo CompareInfo => m_info;
+ internal readonly CompareInfo CompareInfo => m_info;
//
// Advance the Index.
@@ -5561,7 +5561,7 @@ internal bool MatchSpecifiedWord(string target) =>
Index + target.Length <= Length &&
m_info.Compare(Value.Slice(Index, target.Length), target, CompareOptions.IgnoreCase) == 0;
- internal bool MatchSpecifiedWords(string target, bool checkWordBoundary, scoped ref int matchLength)
+ internal readonly bool MatchSpecifiedWords(string target, bool checkWordBoundary, scoped ref int matchLength)
{
int valueRemaining = Value.Length - Index;
matchLength = target.Length;
@@ -5964,7 +5964,7 @@ internal ref struct DTSubString
internal DTSubStringType type;
internal int value;
- internal char this[int relativeIndex] => s[index + relativeIndex];
+ internal readonly char this[int relativeIndex] => s[index + relativeIndex];
}
//
diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/TimeSpanFormat.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/TimeSpanFormat.cs
index 48faa5b1a98345..2f82bb9c6cf9f4 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Globalization/TimeSpanFormat.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/TimeSpanFormat.cs
@@ -465,12 +465,12 @@ internal struct FormatLiterals
private string[] _literals;
- internal string Start => _literals[0];
- internal string DayHourSep => _literals[1];
- internal string HourMinuteSep => _literals[2];
- internal string MinuteSecondSep => _literals[3];
- internal string SecondFractionSep => _literals[4];
- internal string End => _literals[5];
+ internal readonly string Start => _literals[0];
+ internal readonly string DayHourSep => _literals[1];
+ internal readonly string HourMinuteSep => _literals[2];
+ internal readonly string MinuteSecondSep => _literals[3];
+ internal readonly string SecondFractionSep => _literals[4];
+ internal readonly string End => _literals[5];
/* factory method for static invariant FormatLiterals */
internal static FormatLiterals InitInvariant(bool isNegative)
diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/TimeSpanParse.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/TimeSpanParse.cs
index 92a1c75b7dd5c9..b231b39ddd1116 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Globalization/TimeSpanParse.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/TimeSpanParse.cs
@@ -255,7 +255,7 @@ internal TimeSpanToken GetNextToken()
return new TimeSpanToken(TTT.Sep, 0, 0, _value.Slice(startPos, length));
}
- internal bool EOL => _pos >= (_value.Length - 1);
+ internal readonly bool EOL => _pos >= (_value.Length - 1);
internal void BackOne()
{
@@ -302,7 +302,7 @@ internal TimeSpanFormat.FormatLiterals NegativeLocalized
}
}
- internal bool FullAppCompatMatch(TimeSpanFormat.FormatLiterals pattern) =>
+ internal readonly bool FullAppCompatMatch(TimeSpanFormat.FormatLiterals pattern) =>
_sepCount == 5
&& _numCount == 4
&& _literals0.EqualsOrdinal(pattern.Start)
@@ -311,7 +311,7 @@ internal bool FullAppCompatMatch(TimeSpanFormat.FormatLiterals pattern) =>
&& _literals3.EqualsOrdinal(pattern.AppCompatLiteral)
&& _literals4.EqualsOrdinal(pattern.End);
- internal bool PartialAppCompatMatch(TimeSpanFormat.FormatLiterals pattern) =>
+ internal readonly bool PartialAppCompatMatch(TimeSpanFormat.FormatLiterals pattern) =>
_sepCount == 4
&& _numCount == 3
&& _literals0.EqualsOrdinal(pattern.Start)
@@ -320,7 +320,7 @@ internal bool PartialAppCompatMatch(TimeSpanFormat.FormatLiterals pattern) =>
&& _literals3.EqualsOrdinal(pattern.End);
/// DHMSF (all values matched)
- internal bool FullMatch(TimeSpanFormat.FormatLiterals pattern) =>
+ internal readonly bool FullMatch(TimeSpanFormat.FormatLiterals pattern) =>
_sepCount == MaxLiteralTokens
&& _numCount == MaxNumericTokens
&& _literals0.EqualsOrdinal(pattern.Start)
@@ -331,14 +331,14 @@ internal bool FullMatch(TimeSpanFormat.FormatLiterals pattern) =>
&& _literals5.EqualsOrdinal(pattern.End);
/// D (no hours, minutes, seconds, or fractions)
- internal bool FullDMatch(TimeSpanFormat.FormatLiterals pattern) =>
+ internal readonly bool FullDMatch(TimeSpanFormat.FormatLiterals pattern) =>
_sepCount == 2
&& _numCount == 1
&& _literals0.EqualsOrdinal(pattern.Start)
&& _literals1.EqualsOrdinal(pattern.End);
/// HM (no days, seconds, or fractions)
- internal bool FullHMMatch(TimeSpanFormat.FormatLiterals pattern) =>
+ internal readonly bool FullHMMatch(TimeSpanFormat.FormatLiterals pattern) =>
_sepCount == 3
&& _numCount == 2
&& _literals0.EqualsOrdinal(pattern.Start)
@@ -346,7 +346,7 @@ internal bool FullHMMatch(TimeSpanFormat.FormatLiterals pattern) =>
&& _literals2.EqualsOrdinal(pattern.End);
/// DHM (no seconds or fraction)
- internal bool FullDHMMatch(TimeSpanFormat.FormatLiterals pattern) =>
+ internal readonly bool FullDHMMatch(TimeSpanFormat.FormatLiterals pattern) =>
_sepCount == 4
&& _numCount == 3
&& _literals0.EqualsOrdinal(pattern.Start)
@@ -355,7 +355,7 @@ internal bool FullDHMMatch(TimeSpanFormat.FormatLiterals pattern) =>
&& _literals3.EqualsOrdinal(pattern.End);
/// HMS (no days or fraction)
- internal bool FullHMSMatch(TimeSpanFormat.FormatLiterals pattern) =>
+ internal readonly bool FullHMSMatch(TimeSpanFormat.FormatLiterals pattern) =>
_sepCount == 4
&& _numCount == 3
&& _literals0.EqualsOrdinal(pattern.Start)
@@ -364,7 +364,7 @@ internal bool FullHMSMatch(TimeSpanFormat.FormatLiterals pattern) =>
&& _literals3.EqualsOrdinal(pattern.End);
/// DHMS (no fraction)
- internal bool FullDHMSMatch(TimeSpanFormat.FormatLiterals pattern) =>
+ internal readonly bool FullDHMSMatch(TimeSpanFormat.FormatLiterals pattern) =>
_sepCount == 5
&& _numCount == 4
&& _literals0.EqualsOrdinal(pattern.Start)
@@ -374,7 +374,7 @@ internal bool FullDHMSMatch(TimeSpanFormat.FormatLiterals pattern) =>
&& _literals4.EqualsOrdinal(pattern.End);
/// HMSF (no days)
- internal bool FullHMSFMatch(TimeSpanFormat.FormatLiterals pattern) =>
+ internal readonly bool FullHMSFMatch(TimeSpanFormat.FormatLiterals pattern) =>
_sepCount == 5
&& _numCount == 4
&& _literals0.EqualsOrdinal(pattern.Start)
@@ -503,7 +503,7 @@ internal TimeSpanResult(bool throwOnFailure, ReadOnlySpan originalTimeSpan
_originalTimeSpanString = originalTimeSpanString;
}
- internal bool SetNoFormatSpecifierFailure()
+ internal readonly bool SetNoFormatSpecifierFailure()
{
if (!_throwOnFailure)
{
@@ -513,7 +513,7 @@ internal bool SetNoFormatSpecifierFailure()
throw new FormatException(SR.Format_NoFormatSpecifier);
}
- internal bool SetBadQuoteFailure(char failingCharacter)
+ internal readonly bool SetBadQuoteFailure(char failingCharacter)
{
if (!_throwOnFailure)
{
@@ -523,7 +523,7 @@ internal bool SetBadQuoteFailure(char failingCharacter)
throw new FormatException(SR.Format(SR.Format_BadQuote, failingCharacter));
}
- internal bool SetInvalidStringFailure()
+ internal readonly bool SetInvalidStringFailure()
{
if (!_throwOnFailure)
{
@@ -533,7 +533,7 @@ internal bool SetInvalidStringFailure()
throw new FormatException(SR.Format_InvalidString);
}
- internal bool SetArgumentNullFailure(string argumentName)
+ internal readonly bool SetArgumentNullFailure(string argumentName)
{
if (_throwOnFailure)
{
@@ -544,7 +544,7 @@ internal bool SetArgumentNullFailure(string argumentName)
return false;
}
- internal bool SetOverflowFailure()
+ internal readonly bool SetOverflowFailure()
{
if (!_throwOnFailure)
{
@@ -554,7 +554,7 @@ internal bool SetOverflowFailure()
throw new OverflowException(SR.Format(SR.Overflow_TimeSpanElementTooLarge, new string(_originalTimeSpanString)));
}
- internal bool SetBadTimeSpanFailure()
+ internal readonly bool SetBadTimeSpanFailure()
{
if (!_throwOnFailure)
{
@@ -564,7 +564,7 @@ internal bool SetBadTimeSpanFailure()
throw new FormatException(SR.Format(SR.Format_BadTimeSpan, new string(_originalTimeSpanString)));
}
- internal bool SetBadFormatSpecifierFailure(char? formatSpecifierCharacter = null)
+ internal readonly bool SetBadFormatSpecifierFailure(char? formatSpecifierCharacter = null)
{
if (!_throwOnFailure)
{
@@ -1487,7 +1487,7 @@ internal void NextChar()
(char)0;
}
- internal char NextNonDigit()
+ internal readonly char NextNonDigit()
{
int i = _str.Slice(_pos).IndexOfAnyExceptInRange('0', '9');
return i < 0 ? (char)0 : _str[_pos + i];
diff --git a/src/libraries/System.Private.CoreLib/src/System/HashCode.cs b/src/libraries/System.Private.CoreLib/src/System/HashCode.cs
index e11a37af24124a..39c5ec668fe6f3 100644
--- a/src/libraries/System.Private.CoreLib/src/System/HashCode.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/HashCode.cs
@@ -439,7 +439,7 @@ private void Add(int value)
}
}
- public int ToHashCode()
+ public readonly int ToHashCode()
{
// Storing the value of _length locally shaves of quite a few bytes
// in the resulting machine code.
@@ -496,11 +496,11 @@ public int ToHashCode()
[Obsolete("HashCode is a mutable struct and should not be compared with other HashCodes. Use ToHashCode to retrieve the computed hash code.", error: true)]
[EditorBrowsable(EditorBrowsableState.Never)]
- public override int GetHashCode() => throw new NotSupportedException(SR.HashCode_HashCodeNotSupported);
+ public override readonly int GetHashCode() => throw new NotSupportedException(SR.HashCode_HashCodeNotSupported);
[Obsolete("HashCode is a mutable struct and should not be compared with other HashCodes.", error: true)]
[EditorBrowsable(EditorBrowsableState.Never)]
- public override bool Equals(object? obj) => throw new NotSupportedException(SR.HashCode_EqualityNotSupported);
+ public override readonly bool Equals(object? obj) => throw new NotSupportedException(SR.HashCode_EqualityNotSupported);
#pragma warning restore 0809
}
}
diff --git a/src/libraries/System.Private.CoreLib/src/System/IO/Enumeration/FileSystemEntry.Unix.cs b/src/libraries/System.Private.CoreLib/src/System/IO/Enumeration/FileSystemEntry.Unix.cs
index be406ecf507146..687057a7555f92 100644
--- a/src/libraries/System.Private.CoreLib/src/System/IO/Enumeration/FileSystemEntry.Unix.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/IO/Enumeration/FileSystemEntry.Unix.cs
@@ -154,8 +154,8 @@ public FileAttributes Attributes
public bool IsHidden => _status.IsFileSystemEntryHidden(FullPath, FileName);
internal bool IsReadOnly => _status.IsReadOnly(FullPath, continueOnError: true);
- public bool IsDirectory => _isDirectory;
- internal bool IsSymbolicLink => _directoryEntry.InodeType == Interop.Sys.NodeType.DT_LNK;
+ public readonly bool IsDirectory => _isDirectory;
+ internal readonly bool IsSymbolicLink => _directoryEntry.InodeType == Interop.Sys.NodeType.DT_LNK;
public FileSystemInfo ToFileSystemInfo()
{
diff --git a/src/libraries/System.Private.CoreLib/src/System/IO/FileStatus.Unix.cs b/src/libraries/System.Private.CoreLib/src/System/IO/FileStatus.Unix.cs
index 4ffd7cd8cd811c..973e6898f8b657 100644
--- a/src/libraries/System.Private.CoreLib/src/System/IO/FileStatus.Unix.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/IO/FileStatus.Unix.cs
@@ -28,11 +28,11 @@ internal partial struct FileStatus
// Must only be used after calling EnsureCachesInitialized and checking EntryExists is true.
private Interop.Sys.FileStatus _fileCache;
- private bool EntryExists => _state <= InitializedExistsFile;
+ private readonly bool EntryExists => _state <= InitializedExistsFile;
- private bool IsDir => _state == InitializedExistsDir;
+ private readonly bool IsDir => _state == InitializedExistsDir;
- private bool IsBrokenLink => _state == InitializedExistsBrokenLink;
+ private readonly bool IsBrokenLink => _state == InitializedExistsBrokenLink;
// Check if the main path (without following symlinks) has the hidden attribute set.
private bool HasHiddenFlag
@@ -86,7 +86,7 @@ private bool HasReadOnlyFlag
// Must only be used after calling EnsureCachesInitialized.
private int _isReadOnlyCache;
- private bool IsModeReadOnlyCore()
+ private readonly bool IsModeReadOnlyCore()
{
var mode = ((UnixFileMode)_fileCache.Mode & FileSystem.ValidUnixFileModes);
@@ -585,7 +585,7 @@ private static long UnixTimeSecondsToNanoseconds(DateTimeOffset time, long secon
return (time.UtcDateTime.Ticks - DateTimeOffset.UnixEpoch.Ticks - seconds * TimeSpan.TicksPerSecond) * NanosecondsPerTick;
}
- private void ThrowNotFound(string? path)
+ private readonly void ThrowNotFound(string? path)
{
Interop.Error error = _state == InitializedNotExistsNotADir ? Interop.Error.ENOTDIR : Interop.Error.ENOENT;
throw Interop.GetExceptionForIoErrno(new Interop.ErrorInfo(error), path);
diff --git a/src/libraries/System.Private.CoreLib/src/System/MemoryExtensions.cs b/src/libraries/System.Private.CoreLib/src/System/MemoryExtensions.cs
index 174fac083981be..a99640a81b14bb 100644
--- a/src/libraries/System.Private.CoreLib/src/System/MemoryExtensions.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/MemoryExtensions.cs
@@ -4056,11 +4056,11 @@ private static bool TryWrite(Span destination, IForma
/// Gets an enumerator that allows for iteration over the split span.
/// Returns a that can be used to iterate over the split span.
- public SpanSplitEnumerator GetEnumerator() => this;
+ public readonly SpanSplitEnumerator GetEnumerator() => this;
/// Gets the current element of the enumeration.
/// Returns a instance that indicates the bounds of the current element withing the source span.
- public Range Current => new Range(_startCurrent, _endCurrent);
+ public readonly Range Current => new Range(_startCurrent, _endCurrent);
/// Initializes the enumerator for .
internal SpanSplitEnumerator(ReadOnlySpan span, SearchValues searchValues)
diff --git a/src/libraries/System.Private.CoreLib/src/System/Nullable.cs b/src/libraries/System.Private.CoreLib/src/System/Nullable.cs
index 2eb6e5002968a2..49f3c02d41d356 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Nullable.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Nullable.cs
@@ -55,16 +55,16 @@ public readonly T Value
public readonly T GetValueOrDefault(T defaultValue) =>
hasValue ? value : defaultValue;
- public override bool Equals(object? other)
+ public override readonly bool Equals(object? other)
{
if (!hasValue) return other == null;
if (other == null) return false;
return value.Equals(other);
}
- public override int GetHashCode() => hasValue ? value.GetHashCode() : 0;
+ public override readonly int GetHashCode() => hasValue ? value.GetHashCode() : 0;
- public override string? ToString() => hasValue ? value.ToString() : "";
+ public override readonly string? ToString() => hasValue ? value.ToString() : "";
[NonVersionable]
public static implicit operator T?(T value) =>
diff --git a/src/libraries/System.Private.CoreLib/src/System/Number.BigInteger.cs b/src/libraries/System.Private.CoreLib/src/System/Number.BigInteger.cs
index 733faa5320aab3..58a6bceb4d0cec 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Number.BigInteger.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Number.BigInteger.cs
@@ -1083,12 +1083,12 @@ public uint GetBlock(uint index)
return _blocks[index];
}
- public int GetLength()
+ public readonly int GetLength()
{
return _length;
}
- public bool IsZero()
+ public readonly bool IsZero()
{
return _length == 0;
}
diff --git a/src/libraries/System.Private.CoreLib/src/System/ReadOnlySpan.cs b/src/libraries/System.Private.CoreLib/src/System/ReadOnlySpan.cs
index 1402f8d2a3e4e8..1b257e116950a3 100644
--- a/src/libraries/System.Private.CoreLib/src/System/ReadOnlySpan.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/ReadOnlySpan.cs
@@ -260,7 +260,7 @@ public bool MoveNext()
}
/// Gets the element at the current position of the enumerator.
- public ref readonly T Current
+ public readonly ref readonly T Current
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => ref _span[_index];
diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/TypeNameResolver.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/TypeNameResolver.cs
index 04ab8e7ee08598..97d97ce40eb4eb 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Reflection/TypeNameResolver.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/TypeNameResolver.cs
@@ -11,7 +11,7 @@ internal struct TypeNameParseOptions
{
public TypeNameParseOptions() { }
#pragma warning disable CA1822 // Mark members as static
- public int MaxNodes
+ public readonly int MaxNodes
{
get
{
diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncIteratorMethodBuilder.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncIteratorMethodBuilder.cs
index 003047b1990ab9..b3b84fd99b4214 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncIteratorMethodBuilder.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncIteratorMethodBuilder.cs
@@ -27,7 +27,7 @@ public struct AsyncIteratorMethodBuilder
/// The type of the state machine.
/// The state machine instance, passed by reference.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public void MoveNext(ref TStateMachine stateMachine) where TStateMachine : IAsyncStateMachine =>
+ public readonly void MoveNext(ref TStateMachine stateMachine) where TStateMachine : IAsyncStateMachine =>
AsyncMethodBuilderCore.Start(ref stateMachine);
/// Schedules the state machine to proceed to the next action when the specified awaiter completes.
diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncTaskMethodBuilder.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncTaskMethodBuilder.cs
index 7a2734756fd976..02ff492cfc7243 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncTaskMethodBuilder.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncTaskMethodBuilder.cs
@@ -29,14 +29,14 @@ public struct AsyncTaskMethodBuilder
/// The state machine instance, passed by reference.
[DebuggerStepThrough]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public void Start(ref TStateMachine stateMachine) where TStateMachine : IAsyncStateMachine =>
+ public readonly void Start(ref TStateMachine stateMachine) where TStateMachine : IAsyncStateMachine =>
AsyncMethodBuilderCore.Start(ref stateMachine);
/// Associates the builder with the state machine it represents.
/// The heap-allocated state machine object.
/// The argument was null ( in Visual Basic).
/// The builder is incorrectly initialized.
- public void SetStateMachine(IAsyncStateMachine stateMachine) =>
+ public readonly void SetStateMachine(IAsyncStateMachine stateMachine) =>
AsyncMethodBuilderCore.SetStateMachine(stateMachine, task: null);
///
diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncTaskMethodBuilderT.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncTaskMethodBuilderT.cs
index 5a2ccb1d635493..2671ecf71ff541 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncTaskMethodBuilderT.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncTaskMethodBuilderT.cs
@@ -31,14 +31,14 @@ public struct AsyncTaskMethodBuilder
/// The state machine instance, passed by reference.
[DebuggerStepThrough]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public void Start(ref TStateMachine stateMachine) where TStateMachine : IAsyncStateMachine =>
+ public readonly void Start(ref TStateMachine stateMachine) where TStateMachine : IAsyncStateMachine =>
AsyncMethodBuilderCore.Start(ref stateMachine);
/// Associates the builder with the state machine it represents.
/// The heap-allocated state machine object.
/// The argument was null ( in Visual Basic).
/// The builder is incorrectly initialized.
- public void SetStateMachine(IAsyncStateMachine stateMachine) =>
+ public readonly void SetStateMachine(IAsyncStateMachine stateMachine) =>
AsyncMethodBuilderCore.SetStateMachine(stateMachine, m_task);
///
diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncValueTaskMethodBuilder.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncValueTaskMethodBuilder.cs
index 2bd1307cdb999a..a58d56b735be3b 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncValueTaskMethodBuilder.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncValueTaskMethodBuilder.cs
@@ -27,12 +27,12 @@ public struct AsyncValueTaskMethodBuilder
/// The type of the state machine.
/// The state machine instance, passed by reference.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public void Start(ref TStateMachine stateMachine) where TStateMachine : IAsyncStateMachine =>
+ public readonly void Start(ref TStateMachine stateMachine) where TStateMachine : IAsyncStateMachine =>
AsyncMethodBuilderCore.Start(ref stateMachine);
/// Associates the builder with the specified state machine.
/// The state machine instance to associate with the builder.
- public void SetStateMachine(IAsyncStateMachine stateMachine) =>
+ public readonly void SetStateMachine(IAsyncStateMachine stateMachine) =>
AsyncMethodBuilderCore.SetStateMachine(stateMachine, task: null);
/// Marks the task as successfully completed.
diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncValueTaskMethodBuilderT.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncValueTaskMethodBuilderT.cs
index 62499d54e761bf..439790730ce9a9 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncValueTaskMethodBuilderT.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncValueTaskMethodBuilderT.cs
@@ -32,12 +32,12 @@ public struct AsyncValueTaskMethodBuilder
/// The type of the state machine.
/// The state machine instance, passed by reference.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public void Start(ref TStateMachine stateMachine) where TStateMachine : IAsyncStateMachine =>
+ public readonly void Start(ref TStateMachine stateMachine) where TStateMachine : IAsyncStateMachine =>
AsyncMethodBuilderCore.Start(ref stateMachine);
/// Associates the builder with the specified state machine.
/// The state machine instance to associate with the builder.
- public void SetStateMachine(IAsyncStateMachine stateMachine) =>
+ public readonly void SetStateMachine(IAsyncStateMachine stateMachine) =>
AsyncMethodBuilderCore.SetStateMachine(stateMachine, task: null);
/// Marks the value task as successfully completed.
diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncVoidMethodBuilder.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncVoidMethodBuilder.cs
index 0caebcee620366..9e0723df350fd6 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncVoidMethodBuilder.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncVoidMethodBuilder.cs
@@ -36,7 +36,7 @@ public static AsyncVoidMethodBuilder Create()
/// The argument was null ( in Visual Basic).
[DebuggerStepThrough]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public void Start(ref TStateMachine stateMachine) where TStateMachine : IAsyncStateMachine =>
+ public readonly void Start(ref TStateMachine stateMachine) where TStateMachine : IAsyncStateMachine =>
AsyncMethodBuilderCore.Start(ref stateMachine);
/// Associates the builder with the state machine it represents.
diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/CastCache.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/CastCache.cs
index 8b538af931edf1..2eeadf6c36be28 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/CastCache.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/CastCache.cs
@@ -136,7 +136,7 @@ private static ref CastCacheEntry Element(ref int tableData, int index)
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal CastResult TryGet(nuint source, nuint target)
+ internal readonly CastResult TryGet(nuint source, nuint target)
{
// table is always initialized and is not null.
return TryGet(_table!, source, target);
@@ -210,7 +210,7 @@ internal static CastResult TryGet(int[] table, nuint source, nuint target)
// The following helpers must match native implementations in castcache.h and castcache.cpp
// we generally do not OOM in casts, just return null unless throwOnFail is specified.
- private int[]? CreateCastCache(int size, bool throwOnFail = false)
+ private readonly int[]? CreateCastCache(int size, bool throwOnFail = false)
{
// size must be positive
Debug.Assert(size > 1);
diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/DefaultInterpolatedStringHandler.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/DefaultInterpolatedStringHandler.cs
index 1d47cfb2b48706..7804a950146280 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/DefaultInterpolatedStringHandler.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/DefaultInterpolatedStringHandler.cs
@@ -127,7 +127,7 @@ internal void Clear()
}
/// Gets a span of the written characters thus far.
- internal ReadOnlySpan Text => _chars.Slice(0, _pos);
+ internal readonly ReadOnlySpan Text => _chars.Slice(0, _pos);
/// Writes the specified string to the handler.
/// The string to write.
diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/GenericCache.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/GenericCache.cs
index 76764d4ad2c818..b7d1cf2bd7e8d7 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/GenericCache.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/GenericCache.cs
@@ -139,7 +139,7 @@ private static ref Entry Element(Entry[] table, int index)
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal bool TryGet(TKey key, out TValue? value)
+ internal readonly bool TryGet(TKey key, out TValue? value)
{
// table is always initialized and is not null.
Entry[] table = _table!;
@@ -196,7 +196,7 @@ internal bool TryGet(TKey key, out TValue? value)
}
// we generally do not want OOM in cache lookups, just return null unless throwOnFail is specified.
- private Entry[]? CreateCacheTable(int size, bool throwOnFail = false)
+ private readonly Entry[]? CreateCacheTable(int size, bool throwOnFail = false)
{
// size must be positive
Debug.Assert(size > 1);
diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/PoolingAsyncValueTaskMethodBuilder.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/PoolingAsyncValueTaskMethodBuilder.cs
index 9210434e90a16b..76a11a3c7bf876 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/PoolingAsyncValueTaskMethodBuilder.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/PoolingAsyncValueTaskMethodBuilder.cs
@@ -28,13 +28,13 @@ public struct PoolingAsyncValueTaskMethodBuilder
/// The type of the state machine.
/// The state machine instance, passed by reference.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public void Start(ref TStateMachine stateMachine)
+ public readonly void Start(ref TStateMachine stateMachine)
where TStateMachine : IAsyncStateMachine =>
AsyncMethodBuilderCore.Start(ref stateMachine);
/// Associates the builder with the specified state machine.
/// The state machine instance to associate with the builder.
- public void SetStateMachine(IAsyncStateMachine stateMachine) =>
+ public readonly void SetStateMachine(IAsyncStateMachine stateMachine) =>
AsyncMethodBuilderCore.SetStateMachine(stateMachine, task: null);
/// Marks the task as successfully completed.
diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/PoolingAsyncValueTaskMethodBuilderT.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/PoolingAsyncValueTaskMethodBuilderT.cs
index 150f22c1970325..92e3432775ff8a 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/PoolingAsyncValueTaskMethodBuilderT.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/PoolingAsyncValueTaskMethodBuilderT.cs
@@ -37,12 +37,12 @@ public struct PoolingAsyncValueTaskMethodBuilder
/// The type of the state machine.
/// The state machine instance, passed by reference.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public void Start(ref TStateMachine stateMachine) where TStateMachine : IAsyncStateMachine =>
+ public readonly void Start(ref TStateMachine stateMachine) where TStateMachine : IAsyncStateMachine =>
AsyncMethodBuilderCore.Start(ref stateMachine);
/// Associates the builder with the specified state machine.
/// The state machine instance to associate with the builder.
- public void SetStateMachine(IAsyncStateMachine stateMachine) =>
+ public readonly void SetStateMachine(IAsyncStateMachine stateMachine) =>
AsyncMethodBuilderCore.SetStateMachine(stateMachine, task: null);
/// Marks the value task as successfully completed.
diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/GCHandle.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/GCHandle.cs
index 14151c1c02705a..56b6cacadac585 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/GCHandle.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/GCHandle.cs
@@ -78,9 +78,9 @@ public void Free()
}
// Target property - allows getting / updating of the handle's referent.
- public object? Target
+ public readonly object? Target
{
- readonly get
+ get
{
IntPtr handle = _handle;
ThrowIfInvalid(handle);
diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshalling/AnsiStringMarshaller.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshalling/AnsiStringMarshaller.cs
index 34cfccd08755d5..60f3ccf95a40a5 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshalling/AnsiStringMarshaller.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshalling/AnsiStringMarshaller.cs
@@ -97,12 +97,12 @@ public void FromManaged(string? managed, Span buffer)
/// Converts the current managed string to an unmanaged string.
///
/// The converted unmanaged string.
- public byte* ToUnmanaged() => _unmanagedValue;
+ public readonly byte* ToUnmanaged() => _unmanagedValue;
///
/// Frees any allocated unmanaged string memory.
///
- public void Free()
+ public readonly void Free()
{
if (_allocated)
NativeMemory.Free(_unmanagedValue);
diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshalling/ArrayMarshaller.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshalling/ArrayMarshaller.cs
index dc24c7918e90e1..1735875512aeaa 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshalling/ArrayMarshaller.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshalling/ArrayMarshaller.cs
@@ -155,19 +155,19 @@ public void FromManaged(T[]? array, Span buffer)
/// Returns a span that points to the memory where the managed values of the array are stored.
///
/// A span over managed values of the array.
- public ReadOnlySpan GetManagedValuesSource() => _managedArray;
+ public readonly ReadOnlySpan GetManagedValuesSource() => _managedArray;
///
/// Returns a span that points to the memory where the unmanaged values of the array should be stored.
///
/// A span where unmanaged values of the array should be stored.
- public Span GetUnmanagedValuesDestination() => _span;
+ public readonly Span GetUnmanagedValuesDestination() => _span;
///
/// Returns a reference to the marshalled array.
///
/// A pinnable reference to the unmanaged marshalled array.
- public ref TUnmanagedElement GetPinnableReference() => ref MemoryMarshal.GetReference(_span);
+ public readonly ref TUnmanagedElement GetPinnableReference() => ref MemoryMarshal.GetReference(_span);
///
/// Returns the unmanaged value representing the array.
@@ -182,7 +182,7 @@ public void FromManaged(T[]? array, Span buffer)
///
/// Frees resources.
///
- public void Free()
+ public readonly void Free()
{
NativeMemory.Free(_allocatedMemory);
}
diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshalling/BStrStringMarshaller.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshalling/BStrStringMarshaller.cs
index 561f8ce8de3121..c85014a2cc2421 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshalling/BStrStringMarshaller.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshalling/BStrStringMarshaller.cs
@@ -105,12 +105,12 @@ public void FromManaged(string? managed, Span buffer)
/// Converts the current managed string to an unmanaged string.
///
/// The converted unmanaged string.
- public ushort* ToUnmanaged() => _ptrToFirstChar;
+ public readonly ushort* ToUnmanaged() => _ptrToFirstChar;
///
/// Frees any allocated unmanaged string memory.
///
- public void Free()
+ public readonly void Free()
{
if (_allocated)
BStrStringMarshaller.Free(_ptrToFirstChar);
diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshalling/ComVariant.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshalling/ComVariant.cs
index ee44d4960718ce..bc04f7716f6b87 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshalling/ComVariant.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshalling/ComVariant.cs
@@ -81,7 +81,7 @@ private unsafe struct Vector where T : unmanaged
public int _numElements;
public T* _data;
- public Span AsSpan() => new(_data, _numElements);
+ public readonly Span AsSpan() => new(_data, _numElements);
}
[StructLayout(LayoutKind.Sequential)]
diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshalling/PointerArrayMarshaller.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshalling/PointerArrayMarshaller.cs
index 846879583d5ac4..6c2cbf5a703956 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshalling/PointerArrayMarshaller.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshalling/PointerArrayMarshaller.cs
@@ -156,19 +156,19 @@ public void FromManaged(T*[]? array, Span buffer)
/// Returns a span that points to the memory where the managed values of the array are stored.
///
/// A span over managed values of the array.
- public ReadOnlySpan GetManagedValuesSource() => Unsafe.As(_managedArray);
+ public readonly ReadOnlySpan GetManagedValuesSource() => Unsafe.As(_managedArray);
///
/// Returns a span that points to the memory where the unmanaged values of the array should be stored.
///
/// A span where unmanaged values of the array should be stored.
- public Span GetUnmanagedValuesDestination() => _span;
+ public readonly Span GetUnmanagedValuesDestination() => _span;
///
/// Returns a reference to the marshalled array.
///
/// A pinnable reference to the unmanaged marshalled array.
- public ref TUnmanagedElement GetPinnableReference() => ref MemoryMarshal.GetReference(_span);
+ public readonly ref TUnmanagedElement GetPinnableReference() => ref MemoryMarshal.GetReference(_span);
///
/// Returns the unmanaged value representing the array.
@@ -183,7 +183,7 @@ public void FromManaged(T*[]? array, Span buffer)
///
/// Frees resources.
///
- public void Free()
+ public readonly void Free()
{
NativeMemory.Free(_allocatedMemory);
}
diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshalling/ReadOnlySpanMarshaller.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshalling/ReadOnlySpanMarshaller.cs
index 814e3c80c7d0a6..b870efe084639a 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshalling/ReadOnlySpanMarshaller.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshalling/ReadOnlySpanMarshaller.cs
@@ -127,18 +127,18 @@ public void FromManaged(ReadOnlySpan managed, Span buffer)
/// Returns a span that points to the memory where the managed values of the array are stored.
///
/// A span over managed values of the array.
- public ReadOnlySpan GetManagedValuesSource() => _managedArray;
+ public readonly ReadOnlySpan GetManagedValuesSource() => _managedArray;
///
/// Returns a span that points to the memory where the unmanaged values of the array should be stored.
///
/// A span where unmanaged values of the array should be stored.
- public Span GetUnmanagedValuesDestination() => _span;
+ public readonly Span GetUnmanagedValuesDestination() => _span;
///
/// Returns a reference to the marshalled array.
///
- public ref TUnmanagedElement GetPinnableReference() => ref MemoryMarshal.GetReference(_span);
+ public readonly ref TUnmanagedElement GetPinnableReference() => ref MemoryMarshal.GetReference(_span);
///
/// Returns the unmanaged value representing the array.
@@ -152,7 +152,7 @@ public void FromManaged(ReadOnlySpan managed, Span buffer)
///
/// Frees resources.
///
- public void Free()
+ public readonly void Free()
{
NativeMemory.Free(_allocatedMemory);
}
@@ -189,7 +189,7 @@ public void FromUnmanaged(TUnmanagedElement* unmanaged)
/// Returns the managed value representing the native array.
///
/// A span over managed values of the array.
- public ReadOnlySpan ToManaged()
+ public readonly ReadOnlySpan ToManaged()
{
return new ReadOnlySpan(_managedValues!);
}
@@ -199,7 +199,7 @@ public ReadOnlySpan ToManaged()
///
/// The number of elements in the array.
/// A span over unmanaged values of the array.
- public ReadOnlySpan GetUnmanagedValuesSource(int numElements)
+ public readonly ReadOnlySpan GetUnmanagedValuesSource(int numElements)
{
return new ReadOnlySpan(_unmanagedArray, numElements);
}
@@ -218,7 +218,7 @@ public Span GetManagedValuesDestination(int numElements)
///
/// Frees resources.
///
- public void Free()
+ public readonly void Free()
{
Marshal.FreeCoTaskMem((IntPtr)_unmanagedArray);
}
diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshalling/SafeHandleMarshaller.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshalling/SafeHandleMarshaller.cs
index 0e392d1535fd86..1fbe8709ed0d07 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshalling/SafeHandleMarshaller.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshalling/SafeHandleMarshaller.cs
@@ -91,7 +91,7 @@ public void FromManaged(T handle)
/// Retrieve the unmanaged handle.
///
/// The unmanaged handle
- public IntPtr ToUnmanaged() => _originalHandleValue;
+ public readonly IntPtr ToUnmanaged() => _originalHandleValue;
///
/// Initialize the marshaller from an unmanaged handle.
@@ -122,7 +122,7 @@ public void OnInvoked()
/// Retrieve the managed handle from the marshaller.
///
/// The managed handle.
- public T ToManagedFinally() => _handleToReturn!;
+ public readonly T ToManagedFinally() => _handleToReturn!;
///
/// Free any resources and reference counts owned by the marshaller.
@@ -179,7 +179,7 @@ public void FromUnmanaged(IntPtr value)
/// Retrieve the managed handle from the marshaller.
///
/// The managed handle.
- public T ToManaged() => _newHandle;
+ public readonly T ToManaged() => _newHandle;
///
/// Free any resources and reference counts owned by the marshaller.
diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshalling/SpanMarshaller.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshalling/SpanMarshaller.cs
index dc9a22a8fb675a..0421286b74453a 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshalling/SpanMarshaller.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshalling/SpanMarshaller.cs
@@ -154,18 +154,18 @@ public void FromManaged(Span managed, Span buffer)
/// Gets a span that points to the memory where the managed values of the array are stored.
///
/// A span over the managed values of the array.
- public ReadOnlySpan GetManagedValuesSource() => _managedArray;
+ public readonly ReadOnlySpan GetManagedValuesSource() => _managedArray;
///
/// Returns a span that points to the memory where the unmanaged values of the array should be stored.
///
/// A span where unmanaged values of the array should be stored.
- public Span GetUnmanagedValuesDestination() => _span;
+ public readonly Span GetUnmanagedValuesDestination() => _span;
///
/// Returns a reference to the marshalled array.
///
- public ref TUnmanagedElement GetPinnableReference() => ref MemoryMarshal.GetReference(_span);
+ public readonly ref TUnmanagedElement GetPinnableReference() => ref MemoryMarshal.GetReference(_span);
///
/// Returns the unmanaged value representing the array.
@@ -179,7 +179,7 @@ public void FromManaged(Span managed, Span buffer)
///
/// Frees resources.
///
- public void Free()
+ public readonly void Free()
{
NativeMemory.Free(_allocatedMemory);
}
diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshalling/Utf8StringMarshaller.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshalling/Utf8StringMarshaller.cs
index ee231616eaad23..d52dc9ef08d5d9 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshalling/Utf8StringMarshaller.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshalling/Utf8StringMarshaller.cs
@@ -102,12 +102,12 @@ public void FromManaged(string? managed, Span buffer)
/// Converts the current managed string to an unmanaged string.
///
/// An unmanaged string.
- public byte* ToUnmanaged() => _unmanagedValue;
+ public readonly byte* ToUnmanaged() => _unmanagedValue;
///
/// Frees any allocated unmanaged memory.
///
- public void Free()
+ public readonly void Free()
{
if (_allocated)
NativeMemory.Free(_unmanagedValue);
diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.cs
index d4ab9e7a3092eb..e237e4d77a7bf0 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.cs
@@ -590,7 +590,7 @@ internal ContextualReflectionScope(AssemblyLoadContext? activating)
_initialized = true;
}
- public void Dispose()
+ public readonly void Dispose()
{
if (_initialized)
{
diff --git a/src/libraries/System.Private.CoreLib/src/System/SearchValues/ProbabilisticMapState.cs b/src/libraries/System.Private.CoreLib/src/System/SearchValues/ProbabilisticMapState.cs
index fd0296a8c8d990..a240feec6fbfb7 100644
--- a/src/libraries/System.Private.CoreLib/src/System/SearchValues/ProbabilisticMapState.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/SearchValues/ProbabilisticMapState.cs
@@ -60,7 +60,7 @@ public unsafe ProbabilisticMapState(ReadOnlySpan* valuesPtr)
_slowContainsValuesPtr = valuesPtr;
}
- public char[] GetValues()
+ public readonly char[] GetValues()
{
Debug.Assert(_hashEntries is not null);
@@ -71,7 +71,7 @@ public char[] GetValues()
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public bool FastContains(char value)
+ public readonly bool FastContains(char value)
{
Debug.Assert(_hashEntries is not null);
Debug.Assert((IntPtr)_slowContainsValuesPtr == IntPtr.Zero);
@@ -101,7 +101,7 @@ ref Unsafe.As(ref Map),
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- private bool SlowContains(char value)
+ private readonly bool SlowContains(char value)
{
Debug.Assert(_hashEntries is null);
Debug.Assert((IntPtr)_slowContainsValuesPtr != IntPtr.Zero);
diff --git a/src/libraries/System.Private.CoreLib/src/System/Span.cs b/src/libraries/System.Private.CoreLib/src/System/Span.cs
index 92b90b82910e42..d58796eefb4f9c 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Span.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Span.cs
@@ -253,7 +253,7 @@ public bool MoveNext()
}
/// Gets the element at the current position of the enumerator.
- public ref T Current
+ public readonly ref T Current
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => ref _span[_index];
diff --git a/src/libraries/System.Private.CoreLib/src/System/Text/SpanLineEnumerator.cs b/src/libraries/System.Private.CoreLib/src/System/Text/SpanLineEnumerator.cs
index 3741d16eaa200c..d34a6078216ee5 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Text/SpanLineEnumerator.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Text/SpanLineEnumerator.cs
@@ -25,12 +25,12 @@ internal SpanLineEnumerator(ReadOnlySpan buffer)
///
/// Gets the line at the current position of the enumerator.
///
- public ReadOnlySpan Current => _current;
+ public readonly ReadOnlySpan Current => _current;
///
/// Returns this instance as an enumerator.
///
- public SpanLineEnumerator GetEnumerator() => this;
+ public readonly SpanLineEnumerator GetEnumerator() => this;
///
/// Advances the enumerator to the next line of the span.
diff --git a/src/libraries/System.Private.CoreLib/src/System/Text/SpanRuneEnumerator.cs b/src/libraries/System.Private.CoreLib/src/System/Text/SpanRuneEnumerator.cs
index f27b22e4cee95e..1ec33398d2e54c 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Text/SpanRuneEnumerator.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Text/SpanRuneEnumerator.cs
@@ -16,9 +16,9 @@ internal SpanRuneEnumerator(ReadOnlySpan buffer)
_current = default;
}
- public Rune Current => _current;
+ public readonly Rune Current => _current;
- public SpanRuneEnumerator GetEnumerator() => this;
+ public readonly SpanRuneEnumerator GetEnumerator() => this;
public bool MoveNext()
{
diff --git a/src/libraries/System.Private.CoreLib/src/System/Text/StringBuilder.cs b/src/libraries/System.Private.CoreLib/src/System/Text/StringBuilder.cs
index 11b76d7b19568d..e855f71ea2e181 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Text/StringBuilder.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Text/StringBuilder.cs
@@ -535,7 +535,7 @@ public struct ChunkEnumerator
/// Implement IEnumerable.GetEnumerator() to return 'this' as the IEnumerator
///
[EditorBrowsable(EditorBrowsableState.Never)] // Only here to make foreach work
- public ChunkEnumerator GetEnumerator() { return this; }
+ public readonly ChunkEnumerator GetEnumerator() { return this; }
///
/// Implements the IEnumerator pattern.
@@ -566,7 +566,7 @@ public bool MoveNext()
///
/// Implements the IEnumerator pattern.
///
- public ReadOnlyMemory Current
+ public readonly ReadOnlyMemory Current
{
get
{
@@ -2849,7 +2849,7 @@ public AppendInterpolatedStringHandler(int literalLength, int formattedCount, St
/// Writes the specified string to the handler.
/// The string to write.
- public void AppendLiteral(string value) => _stringBuilder.Append(value);
+ public readonly void AppendLiteral(string value) => _stringBuilder.Append(value);
#region AppendFormatted
// Design note:
@@ -3042,13 +3042,13 @@ private void AppendFormattedWithTempSpace(T value, int alignment, string? for
#region AppendFormatted ReadOnlySpan
/// Writes the specified character span to the handler.
/// The span to write.
- public void AppendFormatted(ReadOnlySpan value) => _stringBuilder.Append(value);
+ public readonly void AppendFormatted(ReadOnlySpan value) => _stringBuilder.Append(value);
/// Writes the specified string of chars to the handler.
/// The span to write.
/// Minimum number of characters that should be written for this value. If the value is negative, it indicates left-aligned and the required minimum is the absolute value.
/// The format string.
- public void AppendFormatted(ReadOnlySpan value, int alignment = 0, string? format = null)
+ public readonly void AppendFormatted(ReadOnlySpan value, int alignment = 0, string? format = null)
{
if (alignment == 0)
{
@@ -3126,7 +3126,7 @@ public void AppendFormatted(object? value, int alignment = 0, string? format = n
/// The format string.
/// The type of the value to write.
[MethodImpl(MethodImplOptions.NoInlining)]
- private void AppendCustomFormatter(T value, string? format)
+ private readonly void AppendCustomFormatter(T value, string? format)
{
// This case is very rare, but we need to handle it prior to the other checks in case
// a provider was used that supplied an ICustomFormatter which wanted to intercept the particular value.
diff --git a/src/libraries/System.Private.CoreLib/src/System/Text/StringRuneEnumerator.cs b/src/libraries/System.Private.CoreLib/src/System/Text/StringRuneEnumerator.cs
index ebe0d228b4e01d..bb46dd02120cd3 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Text/StringRuneEnumerator.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Text/StringRuneEnumerator.cs
@@ -20,9 +20,9 @@ internal StringRuneEnumerator(string value)
_nextIndex = 0;
}
- public Rune Current => _current;
+ public readonly Rune Current => _current;
- public StringRuneEnumerator GetEnumerator() => this;
+ public readonly StringRuneEnumerator GetEnumerator() => this;
public bool MoveNext()
{
@@ -49,16 +49,16 @@ public bool MoveNext()
return true;
}
- object? IEnumerator.Current => _current;
+ readonly object? IEnumerator.Current => _current;
- void IDisposable.Dispose()
+ readonly void IDisposable.Dispose()
{
// no-op
}
- IEnumerator IEnumerable.GetEnumerator() => this;
+ readonly IEnumerator IEnumerable.GetEnumerator() => this;
- IEnumerator IEnumerable.GetEnumerator() => this;
+ readonly IEnumerator IEnumerable.GetEnumerator() => this;
void IEnumerator.Reset()
{
diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/ExecutionContext.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/ExecutionContext.cs
index 51e957eb184663..679e9eefe0e483 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Threading/ExecutionContext.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Threading/ExecutionContext.cs
@@ -598,12 +598,12 @@ public override bool Equals([NotNullWhen(true)] object? obj)
return obj is AsyncFlowControl asyncControl && Equals(asyncControl);
}
- public bool Equals(AsyncFlowControl obj)
+ public readonly bool Equals(AsyncFlowControl obj)
{
return _thread == obj._thread;
}
- public override int GetHashCode()
+ public override readonly int GetHashCode()
{
return _thread?.GetHashCode() ?? 0;
}
diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/Lock.NonNativeAot.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/Lock.NonNativeAot.cs
index bd3a0be6902af9..eec0b42de6735f 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Threading/Lock.NonNativeAot.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Threading/Lock.NonNativeAot.cs
@@ -34,7 +34,7 @@ internal partial struct ThreadId
private ulong _id;
public ThreadId(ulong id) => _id = id;
- public ulong Id => _id;
+ public readonly ulong Id => _id;
#else
[ThreadStatic]
private static uint t_threadId;
@@ -45,7 +45,7 @@ internal partial struct ThreadId
public uint Id => _id;
#endif
- public bool IsInitialized => _id != 0;
+ public readonly bool IsInitialized => _id != 0;
public static ThreadId Current_NoInitialize => new ThreadId(t_threadId);
public void InitializeForCurrentThread()
diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/Lock.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/Lock.cs
index 00b879b04c4894..12b465c7bca416 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Threading/Lock.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Threading/Lock.cs
@@ -721,8 +721,8 @@ public State(Lock lockObj) : this(lockObj._state) { }
public static uint InitialStateValue => 0;
public static uint LockedStateValue => IsLockedMask;
private static uint Neg(uint state) => (uint)-(int)state;
- public bool IsInitialState => this == default;
- public bool IsLocked => (_state & IsLockedMask) != 0;
+ public readonly bool IsInitialState => this == default;
+ public readonly bool IsLocked => (_state & IsLockedMask) != 0;
private void SetIsLocked()
{
@@ -730,7 +730,7 @@ private void SetIsLocked()
_state += IsLockedMask;
}
- private bool ShouldNotPreemptWaiters => (_state & ShouldNotPreemptWaitersMask) != 0;
+ private readonly bool ShouldNotPreemptWaiters => (_state & ShouldNotPreemptWaitersMask) != 0;
private void SetShouldNotPreemptWaiters()
{
@@ -755,7 +755,7 @@ private bool ShouldNonWaiterAttemptToAcquireLock
}
}
- private bool HasAnySpinners => (_state & SpinnerCountMask) != 0;
+ private readonly bool HasAnySpinners => (_state & SpinnerCountMask) != 0;
private bool TryIncrementSpinnerCount()
{
@@ -774,7 +774,7 @@ private void DecrementSpinnerCount()
_state -= SpinnerCountIncrement;
}
- private bool IsWaiterSignaledToWake => (_state & IsWaiterSignaledToWakeMask) != 0;
+ private readonly bool IsWaiterSignaledToWake => (_state & IsWaiterSignaledToWakeMask) != 0;
private void SetIsWaiterSignaledToWake()
{
@@ -794,7 +794,7 @@ private void ClearIsWaiterSignaledToWake()
// - Not interruptible by Thread.Interrupt
// - Don't allow reentrance through APCs or message pumping
// - Not forwarded to SynchronizationContext wait overrides
- public bool UseTrivialWaits => (_state & UseTrivialWaitsMask) != 0;
+ public readonly bool UseTrivialWaits => (_state & UseTrivialWaitsMask) != 0;
public static void InitializeUseTrivialWaits(Lock lockObj, bool useTrivialWaits)
{
@@ -806,7 +806,7 @@ public static void InitializeUseTrivialWaits(Lock lockObj, bool useTrivialWaits)
}
}
- public bool HasAnyWaiters => _state >= WaiterCountIncrement;
+ public readonly bool HasAnyWaiters => _state >= WaiterCountIncrement;
private bool TryIncrementWaiterCount()
{
@@ -837,9 +837,9 @@ public bool NeedToSignalWaiter
public static bool operator ==(State state1, State state2) => state1._state == state2._state;
public static bool operator !=(State state1, State state2) => !(state1 == state2);
- bool IEquatable.Equals(State other) => this == other;
- public override bool Equals(object? obj) => obj is State other && this == other;
- public override int GetHashCode() => (int)_state;
+ readonly bool IEquatable.Equals(State other) => this == other;
+ public override readonly bool Equals(object? obj) => obj is State other && this == other;
+ public override readonly int GetHashCode() => (int)_state;
private static State CompareExchange(Lock lockObj, State toState, State fromState) =>
new State(Interlocked.CompareExchange(ref lockObj._state, toState._state, fromState._state));
diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/LowLevelLifoSemaphore.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/LowLevelLifoSemaphore.cs
index 39233c87c15c96..0ff70aa7355563 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Threading/LowLevelLifoSemaphore.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Threading/LowLevelLifoSemaphore.cs
@@ -266,13 +266,13 @@ private struct Counts : IEquatable
private Counts(ulong data) => _data = data;
- private uint GetUInt32Value(byte shift) => (uint)(_data >> shift);
+ private readonly uint GetUInt32Value(byte shift) => (uint)(_data >> shift);
private void SetUInt32Value(uint value, byte shift) =>
_data = (_data & ~((ulong)uint.MaxValue << shift)) | ((ulong)value << shift);
- private ushort GetUInt16Value(byte shift) => (ushort)(_data >> shift);
+ private readonly ushort GetUInt16Value(byte shift) => (ushort)(_data >> shift);
private void SetUInt16Value(ushort value, byte shift) =>
_data = (_data & ~((ulong)ushort.MaxValue << shift)) | ((ulong)value << shift);
- private byte GetByteValue(byte shift) => (byte)(_data >> shift);
+ private readonly byte GetByteValue(byte shift) => (byte)(_data >> shift);
private void SetByteValue(byte value, byte shift) =>
_data = (_data & ~((ulong)byte.MaxValue << shift)) | ((ulong)value << shift);
@@ -367,8 +367,8 @@ public Counts InterlockedCompareExchange(Counts newCounts, Counts oldCounts) =>
public static bool operator !=(Counts lhs, Counts rhs) => !lhs.Equals(rhs);
public override bool Equals([NotNullWhen(true)] object? obj) => obj is Counts other && Equals(other);
- public bool Equals(Counts other) => _data == other._data;
- public override int GetHashCode() => (int)_data + (int)(_data >> 32);
+ public readonly bool Equals(Counts other) => _data == other._data;
+ public override readonly int GetHashCode() => (int)_data + (int)(_data >> 32);
}
[StructLayout(LayoutKind.Sequential)]
diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/LowLevelMonitor.Unix.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/LowLevelMonitor.Unix.cs
index 4b3dfb3be1cc4b..ea81021c3ed391 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Threading/LowLevelMonitor.Unix.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Threading/LowLevelMonitor.Unix.cs
@@ -29,17 +29,17 @@ private void DisposeCore()
_nativeMonitor = IntPtr.Zero;
}
- private void AcquireCore()
+ private readonly void AcquireCore()
{
Interop.Sys.LowLevelMonitor_Acquire(_nativeMonitor);
}
- private void ReleaseCore()
+ private readonly void ReleaseCore()
{
Interop.Sys.LowLevelMonitor_Release(_nativeMonitor);
}
- private void WaitCore()
+ private readonly void WaitCore()
{
Interop.Sys.LowLevelMonitor_Wait(_nativeMonitor);
}
@@ -57,7 +57,7 @@ private bool WaitCore(int timeoutMilliseconds)
return Interop.Sys.LowLevelMonitor_TimedWait(_nativeMonitor, timeoutMilliseconds);
}
- private void Signal_ReleaseCore()
+ private readonly void Signal_ReleaseCore()
{
Interop.Sys.LowLevelMonitor_Signal_Release(_nativeMonitor);
}
diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/LowLevelMonitor.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/LowLevelMonitor.cs
index 3553ab9e707dde..d11783498a1402 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Threading/LowLevelMonitor.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Threading/LowLevelMonitor.cs
@@ -25,7 +25,7 @@ public void Dispose()
}
#if DEBUG
- public bool IsLocked => _ownerThread == Thread.CurrentThread;
+ public readonly bool IsLocked => _ownerThread == Thread.CurrentThread;
#endif
#pragma warning disable CA1822
@@ -46,7 +46,7 @@ public void VerifyIsNotLocked()
}
[Conditional("DEBUG")]
- private void VerifyIsNotLockedByAnyThread()
+ private readonly void VerifyIsNotLockedByAnyThread()
{
#if DEBUG
Debug.Assert(_ownerThread == null);
diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.GateThread.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.GateThread.cs
index 5d1b79a3098e05..5422fb37b52da9 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.GateThread.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.GateThread.cs
@@ -269,7 +269,7 @@ public void SetBlockingAdjustmentTimeAndDelay(int currentTimeMs, uint delayMs)
}
public void ClearBlockingAdjustmentDelay() => _previousBlockingAdjustmentDelayMs = 0;
- public bool HasBlockingAdjustmentDelay => _previousBlockingAdjustmentDelayMs != 0;
+ public readonly bool HasBlockingAdjustmentDelay => _previousBlockingAdjustmentDelayMs != 0;
public uint GetNextDelay(int currentTimeMs)
{
diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.ThreadCounts.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.ThreadCounts.cs
index 26b6ab0cf0ac48..f3c7c0ef99fda5 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.ThreadCounts.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.ThreadCounts.cs
@@ -22,7 +22,7 @@ private struct ThreadCounts : IEquatable
private ThreadCounts(ulong data) => _data = data;
- private short GetInt16Value(byte shift) => (short)(_data >> shift);
+ private readonly short GetInt16Value(byte shift) => (short)(_data >> shift);
private void SetInt16Value(short value, byte shift) =>
_data = (_data & ~((ulong)ushort.MaxValue << shift)) | ((ulong)(ushort)value << shift);
@@ -118,8 +118,8 @@ public ThreadCounts InterlockedCompareExchange(ThreadCounts newCounts, ThreadCou
public static bool operator !=(ThreadCounts lhs, ThreadCounts rhs) => lhs._data != rhs._data;
public override bool Equals([NotNullWhen(true)] object? obj) => obj is ThreadCounts other && Equals(other);
- public bool Equals(ThreadCounts other) => _data == other._data;
- public override int GetHashCode() => (int)_data + (int)(_data >> 32);
+ public readonly bool Equals(ThreadCounts other) => _data == other._data;
+ public override readonly int GetHashCode() => (int)_data + (int)(_data >> 32);
}
}
}
diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.WorkerTracking.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.WorkerTracking.cs
index 8a5f1d8bba581f..27f509c88a25a3 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.WorkerTracking.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.WorkerTracking.cs
@@ -67,7 +67,7 @@ private struct CountsOfThreadsProcessingUserCallbacks : IEquatable _data = data;
- private short GetInt16Value(byte shift) => (short)(_data >> shift);
+ private readonly short GetInt16Value(byte shift) => (short)(_data >> shift);
private void SetInt16Value(short value, byte shift) =>
_data = (_data & ~((uint)ushort.MaxValue << shift)) | ((uint)(ushort)value << shift);
@@ -122,9 +122,9 @@ public CountsOfThreadsProcessingUserCallbacks InterlockedCompareExchange(
public override bool Equals([NotNullWhen(true)] object? obj) =>
obj is CountsOfThreadsProcessingUserCallbacks other && Equals(other);
- public bool Equals(CountsOfThreadsProcessingUserCallbacks other) => _data == other._data;
+ public readonly bool Equals(CountsOfThreadsProcessingUserCallbacks other) => _data == other._data;
- public override int GetHashCode() => (int)_data;
+ public override readonly int GetHashCode() => (int)_data;
}
}
}
diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/ReaderWriterLockSlim.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/ReaderWriterLockSlim.cs
index 0f92e06088f2d4..458cefcd6e2612 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Threading/ReaderWriterLockSlim.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Threading/ReaderWriterLockSlim.cs
@@ -1482,7 +1482,7 @@ private static int GetEnterDeprioritizationStateChange(EnterSpinLockReason reaso
}
}
- private ushort EnterForEnterAnyReadDeprioritizedCount
+ private readonly ushort EnterForEnterAnyReadDeprioritizedCount
{
get
{
@@ -1491,7 +1491,7 @@ private ushort EnterForEnterAnyReadDeprioritizedCount
}
}
- private ushort EnterForEnterAnyWriteDeprioritizedCount
+ private readonly ushort EnterForEnterAnyWriteDeprioritizedCount
{
get
{
@@ -1611,7 +1611,7 @@ public void Exit()
}
#if DEBUG
- public bool IsHeld => _isLocked;
+ public readonly bool IsHeld => _isLocked;
#endif
}
diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/SpinLock.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/SpinLock.cs
index c0eba40cb428af..a00ca41815a18b 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Threading/SpinLock.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Threading/SpinLock.cs
@@ -578,7 +578,7 @@ public bool IsHeldByCurrentThread
}
/// Gets whether thread ownership tracking is enabled for this instance.
- public bool IsThreadOwnerTrackingEnabled => (_owner & LOCK_ID_DISABLE_MASK) == 0;
+ public readonly bool IsThreadOwnerTrackingEnabled => (_owner & LOCK_ID_DISABLE_MASK) == 0;
#region Debugger proxy class
///
diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/SpinWait.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/SpinWait.cs
index 540dbf4c98f8b1..fa2f163b99a71f 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Threading/SpinWait.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Threading/SpinWait.cs
@@ -95,7 +95,7 @@ public struct SpinWait
///
public int Count
{
- get => _count;
+ readonly get => _count;
internal set
{
Debug.Assert(value >= 0);
@@ -113,7 +113,7 @@ internal set
/// On a single-CPU machine, always yields the processor. On machines with
/// multiple CPUs, may yield after an unspecified number of calls.
///
- public bool NextSpinWillYield => _count >= YieldThreshold || Environment.IsSingleProcessor;
+ public readonly bool NextSpinWillYield => _count >= YieldThreshold || Environment.IsSingleProcessor;
///
/// Performs a single spin.
diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Sources/ManualResetValueTaskSourceCore.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Sources/ManualResetValueTaskSourceCore.cs
index c29c5e759f2c1d..69ae018f7f34b1 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Sources/ManualResetValueTaskSourceCore.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Sources/ManualResetValueTaskSourceCore.cs
@@ -43,7 +43,7 @@ public struct ManualResetValueTaskSourceCore
/// Continuations may run asynchronously if this is false, but they'll never run synchronously if this is true.
public bool RunContinuationsAsynchronously
{
- get => _runContinuationsAsynchronously;
+ readonly get => _runContinuationsAsynchronously;
set => _runContinuationsAsynchronously = value;
}
@@ -77,7 +77,7 @@ public void SetException(Exception error)
}
/// Gets the operation version.
- public short Version => _version;
+ public readonly short Version => _version;
/// Gets the status of the operation.
/// Opaque value that was provided to the 's constructor.
@@ -106,7 +106,7 @@ public TResult GetResult(short token)
/// Throws an exception in response to a failed .
[StackTraceHidden]
- private void ThrowForFailedGetResult()
+ private readonly void ThrowForFailedGetResult()
{
_error?.Throw();
throw new InvalidOperationException(); // not using ThrowHelper.ThrowInvalidOperationException so that the JIT sees ThrowForFailedGetResult as always throwing
@@ -198,7 +198,7 @@ public void OnCompleted(Action
/// The object to compare with this instance.
/// if is a .
- public override bool Equals([NotNullWhen(true)] object? obj)
+ public override readonly bool Equals([NotNullWhen(true)] object? obj)
{
return obj is ValueTuple;
}
@@ -47,17 +47,17 @@ public override bool Equals([NotNullWhen(true)] object? obj)
/// Returns a value indicating whether this instance is equal to a specified value.
/// An instance to compare to this instance.
/// true if has the same value as this instance; otherwise, false.
- public bool Equals(ValueTuple other)
+ public readonly bool Equals(ValueTuple other)
{
return true;
}
- bool IStructuralEquatable.Equals(object? other, IEqualityComparer comparer)
+ readonly bool IStructuralEquatable.Equals(object? other, IEqualityComparer comparer)
{
return other is ValueTuple;
}
- int IComparable.CompareTo(object? other)
+ readonly int IComparable.CompareTo(object? other)
{
if (other is null) return 1;
@@ -77,12 +77,12 @@ int IComparable.CompareTo(object? other)
/// instance is equal to , and greater than zero if this instance is greater
/// than .
///
- public int CompareTo(ValueTuple other)
+ public readonly int CompareTo(ValueTuple other)
{
return 0;
}
- int IStructuralComparable.CompareTo(object? other, IComparer comparer)
+ readonly int IStructuralComparable.CompareTo(object? other, IComparer comparer)
{
if (other is null) return 1;
@@ -96,17 +96,17 @@ int IStructuralComparable.CompareTo(object? other, IComparer comparer)
/// Returns the hash code for this instance.
/// A 32-bit signed integer hash code.
- public override int GetHashCode()
+ public override readonly int GetHashCode()
{
return 0;
}
- int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
+ readonly int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
{
return 0;
}
- int IValueTupleInternal.GetHashCode(IEqualityComparer comparer)
+ readonly int IValueTupleInternal.GetHashCode(IEqualityComparer comparer)
{
return 0;
}
@@ -118,12 +118,12 @@ int IValueTupleInternal.GetHashCode(IEqualityComparer comparer)
///
/// The string returned by this method takes the form ().
///
- public override string ToString()
+ public override readonly string ToString()
{
return "()";
}
- string IValueTupleInternal.ToStringEnd()
+ readonly string IValueTupleInternal.ToStringEnd()
{
return ")";
}
@@ -131,12 +131,12 @@ string IValueTupleInternal.ToStringEnd()
///
/// The number of positions in this data structure.
///
- int ITuple.Length => 0;
+ readonly int ITuple.Length => 0;
///
/// Get the element at position .
///
- object? ITuple.this[int index] => throw new IndexOutOfRangeException();
+ readonly object? ITuple.this[int index] => throw new IndexOutOfRangeException();
/// Creates a new struct 0-tuple.
/// A 0-tuple.
@@ -305,16 +305,16 @@ public override bool Equals([NotNullWhen(true)] object? obj)
/// The parameter is considered to be equal to the current instance if each of its field
/// is equal to that of the current instance, using the default comparer for that field's type.
///
- public bool Equals(ValueTuple other)
+ public readonly bool Equals(ValueTuple other)
{
return EqualityComparer.Default.Equals(Item1, other.Item1);
}
- bool IStructuralEquatable.Equals(object? other, IEqualityComparer comparer) =>
+ readonly bool IStructuralEquatable.Equals(object? other, IEqualityComparer comparer) =>
other is ValueTuple vt &&
comparer.Equals(Item1, vt.Item1);
- int IComparable.CompareTo(object? other)
+ readonly int IComparable.CompareTo(object? other)
{
if (other is not null)
{
@@ -337,12 +337,12 @@ int IComparable.CompareTo(object? other)
/// instance is equal to , and greater than zero if this instance is greater
/// than .
///
- public int CompareTo(ValueTuple other)
+ public readonly int CompareTo(ValueTuple other)
{
return Comparer.Default.Compare(Item1, other.Item1);
}
- int IStructuralComparable.CompareTo(object? other, IComparer comparer)
+ readonly int IStructuralComparable.CompareTo(object? other, IComparer comparer)
{
if (other is not null)
{
@@ -361,17 +361,17 @@ int IStructuralComparable.CompareTo(object? other, IComparer comparer)
/// Returns the hash code for the current instance.
///
/// A 32-bit signed integer hash code.
- public override int GetHashCode()
+ public override readonly int GetHashCode()
{
return Item1?.GetHashCode() ?? 0;
}
- int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
+ readonly int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
{
return comparer.GetHashCode(Item1!);
}
- int IValueTupleInternal.GetHashCode(IEqualityComparer comparer)
+ readonly int IValueTupleInternal.GetHashCode(IEqualityComparer comparer)
{
return comparer.GetHashCode(Item1!);
}
@@ -385,12 +385,12 @@ int IValueTupleInternal.GetHashCode(IEqualityComparer comparer)
/// where Item1 represents the value of . If the field is ,
/// it is represented as .
///
- public override string ToString()
+ public override readonly string ToString()
{
return "(" + Item1?.ToString() + ")";
}
- string IValueTupleInternal.ToStringEnd()
+ readonly string IValueTupleInternal.ToStringEnd()
{
return Item1?.ToString() + ")";
}
@@ -398,12 +398,12 @@ string IValueTupleInternal.ToStringEnd()
///
/// The number of positions in this data structure.
///
- int ITuple.Length => 1;
+ readonly int ITuple.Length => 1;
///
/// Get the element at position .
///
- object? ITuple.this[int index]
+ readonly object? ITuple.this[int index]
{
get
{
@@ -476,7 +476,7 @@ public override bool Equals([NotNullWhen(true)] object? obj)
/// The parameter is considered to be equal to the current instance if each of its fields
/// are equal to that of the current instance, using the default comparer for that field's type.
///
- public bool Equals(ValueTuple other)
+ public readonly bool Equals(ValueTuple other)
{
return EqualityComparer.Default.Equals(Item1, other.Item1)
&& EqualityComparer.Default.Equals(Item2, other.Item2);
@@ -500,7 +500,7 @@ public bool Equals(ValueTuple other)
/// implementation. If this method call returns , the method is
/// called again and passed the values of the two instances.
///
- bool IStructuralEquatable.Equals(object? other, IEqualityComparer comparer) =>
+ readonly bool IStructuralEquatable.Equals(object? other, IEqualityComparer comparer) =>
other is ValueTuple vt &&
comparer.Equals(Item1, vt.Item1) &&
comparer.Equals(Item2, vt.Item2);
@@ -528,7 +528,7 @@ int IComparable.CompareTo(object? other)
/// instance is equal to , and greater than zero if this instance is greater
/// than .
///
- public int CompareTo(ValueTuple other)
+ public readonly int CompareTo(ValueTuple other)
{
int c = Comparer.Default.Compare(Item1, other.Item1);
if (c != 0) return c;
@@ -536,7 +536,7 @@ public int CompareTo(ValueTuple other)
return Comparer.Default.Compare(Item2, other.Item2);
}
- int IStructuralComparable.CompareTo(object? other, IComparer comparer)
+ readonly int IStructuralComparable.CompareTo(object? other, IComparer comparer)
{
if (other is not null)
{
@@ -558,7 +558,7 @@ int IStructuralComparable.CompareTo(object? other, IComparer comparer)
/// Returns the hash code for the current instance.
///
/// A 32-bit signed integer hash code.
- public override int GetHashCode()
+ public override readonly int GetHashCode()
{
return HashCode.Combine(Item1?.GetHashCode() ?? 0,
Item2?.GetHashCode() ?? 0);
@@ -569,7 +569,7 @@ int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
return GetHashCodeCore(comparer);
}
- private int GetHashCodeCore(IEqualityComparer comparer)
+ private readonly int GetHashCodeCore(IEqualityComparer comparer)
{
return HashCode.Combine(comparer.GetHashCode(Item1!),
comparer.GetHashCode(Item2!));
@@ -590,12 +590,12 @@ int IValueTupleInternal.GetHashCode(IEqualityComparer comparer)
/// and fields. If either field value is ,
/// it is represented as .
///
- public override string ToString()
+ public override readonly string ToString()
{
return "(" + Item1?.ToString() + ", " + Item2?.ToString() + ")";
}
- string IValueTupleInternal.ToStringEnd()
+ readonly string IValueTupleInternal.ToStringEnd()
{
return Item1?.ToString() + ", " + Item2?.ToString() + ")";
}
@@ -603,12 +603,12 @@ string IValueTupleInternal.ToStringEnd()
///
/// The number of positions in this data structure.
///
- int ITuple.Length => 2;
+ readonly int ITuple.Length => 2;
///
/// Get the element at position .
///
- object? ITuple.this[int index] =>
+ readonly object? ITuple.this[int index] =>
index switch
{
0 => Item1,
@@ -683,14 +683,14 @@ public override bool Equals([NotNullWhen(true)] object? obj)
/// The parameter is considered to be equal to the current instance if each of its fields
/// are equal to that of the current instance, using the default comparer for that field's type.
///
- public bool Equals(ValueTuple other)
+ public readonly bool Equals(ValueTuple other)
{
return EqualityComparer.Default.Equals(Item1, other.Item1)
&& EqualityComparer.Default.Equals(Item2, other.Item2)
&& EqualityComparer.Default.Equals(Item3, other.Item3);
}
- bool IStructuralEquatable.Equals(object? other, IEqualityComparer comparer) =>
+ readonly bool IStructuralEquatable.Equals(object? other, IEqualityComparer comparer) =>
other is ValueTuple vt &&
comparer.Equals(Item1, vt.Item1) &&
comparer.Equals(Item2, vt.Item2) &&
@@ -719,7 +719,7 @@ int IComparable.CompareTo(object? other)
/// instance is equal to , and greater than zero if this instance is greater
/// than .
///
- public int CompareTo(ValueTuple other)
+ public readonly int CompareTo(ValueTuple other)
{
int c = Comparer.Default.Compare(Item1, other.Item1);
if (c != 0) return c;
@@ -730,7 +730,7 @@ public int CompareTo(ValueTuple other)
return Comparer.Default.Compare(Item3, other.Item3);
}
- int IStructuralComparable.CompareTo(object? other, IComparer comparer)
+ readonly int IStructuralComparable.CompareTo(object? other, IComparer comparer)
{
if (other is not null)
{
@@ -755,7 +755,7 @@ int IStructuralComparable.CompareTo(object? other, IComparer comparer)
/// Returns the hash code for the current instance.
///
/// A 32-bit signed integer hash code.
- public override int GetHashCode()
+ public override readonly int GetHashCode()
{
return HashCode.Combine(Item1?.GetHashCode() ?? 0,
Item2?.GetHashCode() ?? 0,
@@ -767,7 +767,7 @@ int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
return GetHashCodeCore(comparer);
}
- private int GetHashCodeCore(IEqualityComparer comparer)
+ private readonly int GetHashCodeCore(IEqualityComparer comparer)
{
return HashCode.Combine(comparer.GetHashCode(Item1!),
comparer.GetHashCode(Item2!),
@@ -787,12 +787,12 @@ int IValueTupleInternal.GetHashCode(IEqualityComparer comparer)
/// The string returned by this method takes the form (Item1, Item2, Item3).
/// If any field value is , it is represented as .
///
- public override string ToString()
+ public override readonly string ToString()
{
return "(" + Item1?.ToString() + ", " + Item2?.ToString() + ", " + Item3?.ToString() + ")";
}
- string IValueTupleInternal.ToStringEnd()
+ readonly string IValueTupleInternal.ToStringEnd()
{
return Item1?.ToString() + ", " + Item2?.ToString() + ", " + Item3?.ToString() + ")";
}
@@ -800,12 +800,12 @@ string IValueTupleInternal.ToStringEnd()
///
/// The number of positions in this data structure.
///
- int ITuple.Length => 3;
+ readonly int ITuple.Length => 3;
///
/// Get the element at position .
///
- object? ITuple.this[int index] =>
+ readonly object? ITuple.this[int index] =>
index switch
{
0 => Item1,
@@ -888,7 +888,7 @@ public override bool Equals([NotNullWhen(true)] object? obj)
/// The parameter is considered to be equal to the current instance if each of its fields
/// are equal to that of the current instance, using the default comparer for that field's type.
///
- public bool Equals(ValueTuple other)
+ public readonly bool Equals(ValueTuple other)
{
return EqualityComparer.Default.Equals(Item1, other.Item1)
&& EqualityComparer.Default.Equals(Item2, other.Item2)
@@ -896,7 +896,7 @@ public bool Equals(ValueTuple other)
&& EqualityComparer.Default.Equals(Item4, other.Item4);
}
- bool IStructuralEquatable.Equals(object? other, IEqualityComparer comparer) =>
+ readonly bool IStructuralEquatable.Equals(object? other, IEqualityComparer comparer) =>
other is ValueTuple vt &&
comparer.Equals(Item1, vt.Item1) &&
comparer.Equals(Item2, vt.Item2) &&
@@ -926,7 +926,7 @@ int IComparable.CompareTo(object? other)
/// instance is equal to , and greater than zero if this instance is greater
/// than .
///
- public int CompareTo(ValueTuple other)
+ public readonly int CompareTo(ValueTuple other)
{
int c = Comparer.Default.Compare(Item1, other.Item1);
if (c != 0) return c;
@@ -940,7 +940,7 @@ public int CompareTo(ValueTuple other)
return Comparer.Default.Compare(Item4, other.Item4);
}
- int IStructuralComparable.CompareTo(object? other, IComparer comparer)
+ readonly int IStructuralComparable.CompareTo(object? other, IComparer comparer)
{
if (other is not null)
{
@@ -968,7 +968,7 @@ int IStructuralComparable.CompareTo(object? other, IComparer comparer)
/// Returns the hash code for the current instance.
///
/// A 32-bit signed integer hash code.
- public override int GetHashCode()
+ public override readonly int GetHashCode()
{
return HashCode.Combine(Item1?.GetHashCode() ?? 0,
Item2?.GetHashCode() ?? 0,
@@ -981,7 +981,7 @@ int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
return GetHashCodeCore(comparer);
}
- private int GetHashCodeCore(IEqualityComparer comparer)
+ private readonly int GetHashCodeCore(IEqualityComparer comparer)
{
return HashCode.Combine(comparer.GetHashCode(Item1!),
comparer.GetHashCode(Item2!),
@@ -1002,12 +1002,12 @@ int IValueTupleInternal.GetHashCode(IEqualityComparer comparer)
/// The string returned by this method takes the form (Item1, Item2, Item3, Item4).
/// If any field value is , it is represented as .
///
- public override string ToString()
+ public override readonly string ToString()
{
return "(" + Item1?.ToString() + ", " + Item2?.ToString() + ", " + Item3?.ToString() + ", " + Item4?.ToString() + ")";
}
- string IValueTupleInternal.ToStringEnd()
+ readonly string IValueTupleInternal.ToStringEnd()
{
return Item1?.ToString() + ", " + Item2?.ToString() + ", " + Item3?.ToString() + ", " + Item4?.ToString() + ")";
}
@@ -1015,12 +1015,12 @@ string IValueTupleInternal.ToStringEnd()
///
/// The number of positions in this data structure.
///
- int ITuple.Length => 4;
+ readonly int ITuple.Length => 4;
///
/// Get the element at position .
///
- object? ITuple.this[int index] =>
+ readonly object? ITuple.this[int index] =>
index switch
{
0 => Item1,
@@ -1111,7 +1111,7 @@ public override bool Equals([NotNullWhen(true)] object? obj)
/// The parameter is considered to be equal to the current instance if each of its fields
/// are equal to that of the current instance, using the default comparer for that field's type.
///
- public bool Equals(ValueTuple other)
+ public readonly bool Equals(ValueTuple other)
{
return EqualityComparer.Default.Equals(Item1, other.Item1)
&& EqualityComparer.Default.Equals(Item2, other.Item2)
@@ -1120,7 +1120,7 @@ public bool Equals(ValueTuple other)
&& EqualityComparer.Default.Equals(Item5, other.Item5);
}
- bool IStructuralEquatable.Equals(object? other, IEqualityComparer comparer) =>
+ readonly bool IStructuralEquatable.Equals(object? other, IEqualityComparer comparer) =>
other is ValueTuple vt &&
comparer.Equals(Item1, vt.Item1) &&
comparer.Equals(Item2, vt.Item2) &&
@@ -1151,7 +1151,7 @@ int IComparable.CompareTo(object? other)
/// instance is equal to , and greater than zero if this instance is greater
/// than .
///
- public int CompareTo(ValueTuple other)
+ public readonly int CompareTo(ValueTuple other)
{
int c = Comparer.Default.Compare(Item1, other.Item1);
if (c != 0) return c;
@@ -1168,7 +1168,7 @@ public int CompareTo(ValueTuple other)
return Comparer.Default.Compare(Item5, other.Item5);
}
- int IStructuralComparable.CompareTo(object? other, IComparer comparer)
+ readonly int IStructuralComparable.CompareTo(object? other, IComparer comparer)
{
if (other is not null)
{
@@ -1199,7 +1199,7 @@ int IStructuralComparable.CompareTo(object? other, IComparer comparer)
/// Returns the hash code for the current instance.
///
/// A 32-bit signed integer hash code.
- public override int GetHashCode()
+ public override readonly int GetHashCode()
{
return HashCode.Combine(Item1?.GetHashCode() ?? 0,
Item2?.GetHashCode() ?? 0,
@@ -1213,7 +1213,7 @@ int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
return GetHashCodeCore(comparer);
}
- private int GetHashCodeCore(IEqualityComparer comparer)
+ private readonly int GetHashCodeCore(IEqualityComparer comparer)
{
return HashCode.Combine(comparer.GetHashCode(Item1!),
comparer.GetHashCode(Item2!),
@@ -1235,12 +1235,12 @@ int IValueTupleInternal.GetHashCode(IEqualityComparer comparer)
/// The string returned by this method takes the form (Item1, Item2, Item3, Item4, Item5).
/// If any field value is , it is represented as .
///
- public override string ToString()
+ public override readonly string ToString()
{
return "(" + Item1?.ToString() + ", " + Item2?.ToString() + ", " + Item3?.ToString() + ", " + Item4?.ToString() + ", " + Item5?.ToString() + ")";
}
- string IValueTupleInternal.ToStringEnd()
+ readonly string IValueTupleInternal.ToStringEnd()
{
return Item1?.ToString() + ", " + Item2?.ToString() + ", " + Item3?.ToString() + ", " + Item4?.ToString() + ", " + Item5?.ToString() + ")";
}
@@ -1248,12 +1248,12 @@ string IValueTupleInternal.ToStringEnd()
///
/// The number of positions in this data structure.
///
- int ITuple.Length => 5;
+ readonly int ITuple.Length => 5;
///
/// Get the element at position .
///
- object? ITuple.this[int index] =>
+ readonly object? ITuple.this[int index] =>
index switch
{
0 => Item1,
@@ -1352,7 +1352,7 @@ public override bool Equals([NotNullWhen(true)] object? obj)
/// The parameter is considered to be equal to the current instance if each of its fields
/// are equal to that of the current instance, using the default comparer for that field's type.
///
- public bool Equals(ValueTuple other)
+ public readonly bool Equals(ValueTuple other)
{
return EqualityComparer.Default.Equals(Item1, other.Item1)
&& EqualityComparer.Default.Equals(Item2, other.Item2)
@@ -1362,7 +1362,7 @@ public bool Equals(ValueTuple other)
&& EqualityComparer.Default.Equals(Item6, other.Item6);
}
- bool IStructuralEquatable.Equals(object? other, IEqualityComparer comparer) =>
+ readonly bool IStructuralEquatable.Equals(object? other, IEqualityComparer comparer) =>
other is ValueTuple vt &&
comparer.Equals(Item1, vt.Item1) &&
comparer.Equals(Item2, vt.Item2) &&
@@ -1394,7 +1394,7 @@ int IComparable.CompareTo(object? other)
/// instance is equal to , and greater than zero if this instance is greater
/// than .
///
- public int CompareTo(ValueTuple other)
+ public readonly int CompareTo(ValueTuple other)
{
int c = Comparer.Default.Compare(Item1, other.Item1);
if (c != 0) return c;
@@ -1414,7 +1414,7 @@ public int CompareTo(ValueTuple other)
return Comparer.Default.Compare(Item6, other.Item6);
}
- int IStructuralComparable.CompareTo(object? other, IComparer comparer)
+ readonly int IStructuralComparable.CompareTo(object? other, IComparer comparer)
{
if (other is not null)
{
@@ -1448,7 +1448,7 @@ int IStructuralComparable.CompareTo(object? other, IComparer comparer)
/// Returns the hash code for the current instance.
///
/// A 32-bit signed integer hash code.
- public override int GetHashCode()
+ public override readonly int GetHashCode()
{
return HashCode.Combine(Item1?.GetHashCode() ?? 0,
Item2?.GetHashCode() ?? 0,
@@ -1463,7 +1463,7 @@ int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
return GetHashCodeCore(comparer);
}
- private int GetHashCodeCore(IEqualityComparer comparer)
+ private readonly int GetHashCodeCore(IEqualityComparer comparer)
{
return HashCode.Combine(comparer.GetHashCode(Item1!),
comparer.GetHashCode(Item2!),
@@ -1486,12 +1486,12 @@ int IValueTupleInternal.GetHashCode(IEqualityComparer comparer)
/// The string returned by this method takes the form (Item1, Item2, Item3, Item4, Item5, Item6).
/// If any field value is , it is represented as .
///
- public override string ToString()
+ public override readonly string ToString()
{
return "(" + Item1?.ToString() + ", " + Item2?.ToString() + ", " + Item3?.ToString() + ", " + Item4?.ToString() + ", " + Item5?.ToString() + ", " + Item6?.ToString() + ")";
}
- string IValueTupleInternal.ToStringEnd()
+ readonly string IValueTupleInternal.ToStringEnd()
{
return Item1?.ToString() + ", " + Item2?.ToString() + ", " + Item3?.ToString() + ", " + Item4?.ToString() + ", " + Item5?.ToString() + ", " + Item6?.ToString() + ")";
}
@@ -1499,12 +1499,12 @@ string IValueTupleInternal.ToStringEnd()
///
/// The number of positions in this data structure.
///
- int ITuple.Length => 6;
+ readonly int ITuple.Length => 6;
///
/// Get the element at position .
///
- object? ITuple.this[int index] =>
+ readonly object? ITuple.this[int index] =>
index switch
{
0 => Item1,
@@ -1611,7 +1611,7 @@ public override bool Equals([NotNullWhen(true)] object? obj)
/// The parameter is considered to be equal to the current instance if each of its fields
/// are equal to that of the current instance, using the default comparer for that field's type.
///
- public bool Equals(ValueTuple other)
+ public readonly bool Equals(ValueTuple other)
{
return EqualityComparer.Default.Equals(Item1, other.Item1)
&& EqualityComparer.Default.Equals(Item2, other.Item2)
@@ -1622,7 +1622,7 @@ public bool Equals(ValueTuple other)
&& EqualityComparer.Default.Equals(Item7, other.Item7);
}
- bool IStructuralEquatable.Equals(object? other, IEqualityComparer comparer) =>
+ readonly bool IStructuralEquatable.Equals(object? other, IEqualityComparer comparer) =>
other is ValueTuple vt &&
comparer.Equals(Item1, vt.Item1) &&
comparer.Equals(Item2, vt.Item2) &&
@@ -1655,7 +1655,7 @@ int IComparable.CompareTo(object? other)
/// instance is equal to , and greater than zero if this instance is greater
/// than .
///
- public int CompareTo(ValueTuple other)
+ public readonly int CompareTo(ValueTuple other)
{
int c = Comparer.Default.Compare(Item1, other.Item1);
if (c != 0) return c;
@@ -1678,7 +1678,7 @@ public int CompareTo(ValueTuple other)
return Comparer.Default.Compare(Item7, other.Item7);
}
- int IStructuralComparable.CompareTo(object? other, IComparer comparer)
+ readonly int IStructuralComparable.CompareTo(object? other, IComparer comparer)
{
if (other is not null)
{
@@ -1715,7 +1715,7 @@ int IStructuralComparable.CompareTo(object? other, IComparer comparer)
/// Returns the hash code for the current instance.
///
/// A 32-bit signed integer hash code.
- public override int GetHashCode()
+ public override readonly int GetHashCode()
{
return HashCode.Combine(Item1?.GetHashCode() ?? 0,
Item2?.GetHashCode() ?? 0,
@@ -1731,7 +1731,7 @@ int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
return GetHashCodeCore(comparer);
}
- private int GetHashCodeCore(IEqualityComparer comparer)
+ private readonly int GetHashCodeCore(IEqualityComparer comparer)
{
return HashCode.Combine(comparer.GetHashCode(Item1!),
comparer.GetHashCode(Item2!),
@@ -1755,12 +1755,12 @@ int IValueTupleInternal.GetHashCode(IEqualityComparer comparer)
/// The string returned by this method takes the form (Item1, Item2, Item3, Item4, Item5, Item6, Item7).
/// If any field value is , it is represented as .
///
- public override string ToString()
+ public override readonly string ToString()
{
return "(" + Item1?.ToString() + ", " + Item2?.ToString() + ", " + Item3?.ToString() + ", " + Item4?.ToString() + ", " + Item5?.ToString() + ", " + Item6?.ToString() + ", " + Item7?.ToString() + ")";
}
- string IValueTupleInternal.ToStringEnd()
+ readonly string IValueTupleInternal.ToStringEnd()
{
return Item1?.ToString() + ", " + Item2?.ToString() + ", " + Item3?.ToString() + ", " + Item4?.ToString() + ", " + Item5?.ToString() + ", " + Item6?.ToString() + ", " + Item7?.ToString() + ")";
}
@@ -1768,12 +1768,12 @@ string IValueTupleInternal.ToStringEnd()
///
/// The number of positions in this data structure.
///
- int ITuple.Length => 7;
+ readonly int ITuple.Length => 7;
///
/// Get the element at position .
///
- object? ITuple.this[int index] =>
+ readonly object? ITuple.this[int index] =>
index switch
{
0 => Item1,
@@ -1894,7 +1894,7 @@ public override bool Equals([NotNullWhen(true)] object? obj)
/// The parameter is considered to be equal to the current instance if each of its fields
/// are equal to that of the current instance, using the default comparer for that field's type.
///
- public bool Equals(ValueTuple other)
+ public readonly bool Equals(ValueTuple other)
{
return EqualityComparer.Default.Equals(Item1, other.Item1)
&& EqualityComparer.Default.Equals(Item2, other.Item2)
@@ -1906,7 +1906,7 @@ public bool Equals(ValueTuple other)
&& EqualityComparer.Default.Equals(Rest, other.Rest);
}
- bool IStructuralEquatable.Equals(object? other, IEqualityComparer comparer) =>
+ readonly bool IStructuralEquatable.Equals(object? other, IEqualityComparer comparer) =>
other is ValueTuple vt &&
comparer.Equals(Item1, vt.Item1) &&
comparer.Equals(Item2, vt.Item2) &&
@@ -1940,7 +1940,7 @@ int IComparable.CompareTo(object? other)
/// instance is equal to , and greater than zero if this instance is greater
/// than .
///
- public int CompareTo(ValueTuple other)
+ public readonly int CompareTo(ValueTuple other)
{
int c = Comparer.Default.Compare(Item1, other.Item1);
if (c != 0) return c;
@@ -1966,7 +1966,7 @@ public int CompareTo(ValueTuple other)
return Comparer.Default.Compare(Rest, other.Rest);
}
- int IStructuralComparable.CompareTo(object? other, IComparer comparer)
+ readonly int IStructuralComparable.CompareTo(object? other, IComparer comparer)
{
if (other is not null)
{
@@ -2006,7 +2006,7 @@ int IStructuralComparable.CompareTo(object? other, IComparer comparer)
/// Returns the hash code for the current instance.
///
/// A 32-bit signed integer hash code.
- public override int GetHashCode()
+ public override readonly int GetHashCode()
{
// We want to have a limited hash in this case. We'll use the first 7 elements of the tuple
if (Rest is not IValueTupleInternal)
@@ -2085,7 +2085,7 @@ int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
return GetHashCodeCore(comparer);
}
- private int GetHashCodeCore(IEqualityComparer comparer)
+ private readonly int GetHashCodeCore(IEqualityComparer comparer)
{
// We want to have a limited hash in this case. We'll use the first 7 elements of the tuple
if (Rest is not IValueTupleInternal rest)
@@ -2168,7 +2168,7 @@ int IValueTupleInternal.GetHashCode(IEqualityComparer comparer)
/// The string returned by this method takes the form (Item1, Item2, Item3, Item4, Item5, Item6, Item7, Rest).
/// If any field value is , it is represented as .
///
- public override string ToString()
+ public override readonly string ToString()
{
if (Rest is IValueTupleInternal)
{
@@ -2178,7 +2178,7 @@ public override string ToString()
return "(" + Item1?.ToString() + ", " + Item2?.ToString() + ", " + Item3?.ToString() + ", " + Item4?.ToString() + ", " + Item5?.ToString() + ", " + Item6?.ToString() + ", " + Item7?.ToString() + ", " + Rest.ToString() + ")";
}
- string IValueTupleInternal.ToStringEnd()
+ readonly string IValueTupleInternal.ToStringEnd()
{
if (Rest is IValueTupleInternal)
{
@@ -2191,12 +2191,12 @@ string IValueTupleInternal.ToStringEnd()
///
/// The number of positions in this data structure.
///
- int ITuple.Length => Rest is IValueTupleInternal ? 7 + ((IValueTupleInternal)Rest).Length : 8;
+ readonly int ITuple.Length => Rest is IValueTupleInternal ? 7 + ((IValueTupleInternal)Rest).Length : 8;
///
/// Get the element at position .
///
- object? ITuple.this[int index]
+ readonly object? ITuple.this[int index]
{
get
{