diff --git a/src/mscorlib/shared/System/Collections/Generic/KeyValuePair.cs b/src/mscorlib/shared/System/Collections/Generic/KeyValuePair.cs index aeafecd95807..82c786d407c3 100644 --- a/src/mscorlib/shared/System/Collections/Generic/KeyValuePair.cs +++ b/src/mscorlib/shared/System/Collections/Generic/KeyValuePair.cs @@ -47,10 +47,10 @@ internal static string PairToString(object key, object value) // and IReadOnlyDictionary. [Serializable] [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")] - public struct KeyValuePair + public readonly struct KeyValuePair { - private TKey key; // Do not rename (binary serialization) - private TValue value; // Do not rename (binary serialization) + private readonly TKey key; // Do not rename (binary serialization) + private readonly TValue value; // Do not rename (binary serialization) public KeyValuePair(TKey key, TValue value) { diff --git a/src/mscorlib/shared/System/DateTime.cs b/src/mscorlib/shared/System/DateTime.cs index ad4d3a0fd363..d3720b28e453 100644 --- a/src/mscorlib/shared/System/DateTime.cs +++ b/src/mscorlib/shared/System/DateTime.cs @@ -53,7 +53,7 @@ namespace System [StructLayout(LayoutKind.Auto)] [Serializable] [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")] - public partial struct DateTime : IComparable, IFormattable, IConvertible, IComparable, IEquatable, ISerializable + public readonly partial struct DateTime : IComparable, IFormattable, IConvertible, IComparable, IEquatable, ISerializable { // Number of 100ns ticks per time unit private const long TicksPerMillisecond = 10000; @@ -135,7 +135,7 @@ public partial struct DateTime : IComparable, IFormattable, IConvertible, ICompa // savings time hour and it is in daylight savings time. This allows distinction of these // otherwise ambiguous local times and prevents data loss when round tripping from Local to // UTC time. - private UInt64 _dateData; + private readonly UInt64 _dateData; // Constructs a DateTime from a tick count. The ticks // argument specifies the date as the number of 100-nanosecond intervals diff --git a/src/mscorlib/shared/System/Diagnostics/Tracing/TraceLogging/PropertyValue.cs b/src/mscorlib/shared/System/Diagnostics/Tracing/TraceLogging/PropertyValue.cs index 854bc06bb690..cff424dad656 100644 --- a/src/mscorlib/shared/System/Diagnostics/Tracing/TraceLogging/PropertyValue.cs +++ b/src/mscorlib/shared/System/Diagnostics/Tracing/TraceLogging/PropertyValue.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Reflection; using System.Runtime.InteropServices; using System.Diagnostics; @@ -27,7 +27,7 @@ namespace System.Diagnostics.Tracing #else internal #endif - unsafe struct PropertyValue + unsafe readonly struct PropertyValue { /// /// Union of well-known value types, to avoid boxing those types. diff --git a/src/mscorlib/shared/System/Globalization/DaylightTime.cs b/src/mscorlib/shared/System/Globalization/DaylightTime.cs index 10f074dc24e4..e6920b366602 100644 --- a/src/mscorlib/shared/System/Globalization/DaylightTime.cs +++ b/src/mscorlib/shared/System/Globalization/DaylightTime.cs @@ -33,7 +33,7 @@ public DaylightTime(DateTime start, DateTime end, TimeSpan delta) } // Value type version of DaylightTime - internal struct DaylightTimeStruct + internal readonly struct DaylightTimeStruct { public DaylightTimeStruct(DateTime start, DateTime end, TimeSpan delta) { diff --git a/src/mscorlib/shared/System/ParamsArray.cs b/src/mscorlib/shared/System/ParamsArray.cs index 1c73bc585649..043ee679eef3 100644 --- a/src/mscorlib/shared/System/ParamsArray.cs +++ b/src/mscorlib/shared/System/ParamsArray.cs @@ -4,7 +4,7 @@ namespace System { - internal struct ParamsArray + internal readonly struct ParamsArray { // Sentinel fixed-length arrays eliminate the need for a "count" field keeping this // struct down to just 4 fields. These are only used for their "Length" property, diff --git a/src/mscorlib/shared/System/Reflection/ParameterModifier.cs b/src/mscorlib/shared/System/Reflection/ParameterModifier.cs index 640fee284aec..0fb75ffbd88f 100644 --- a/src/mscorlib/shared/System/Reflection/ParameterModifier.cs +++ b/src/mscorlib/shared/System/Reflection/ParameterModifier.cs @@ -4,7 +4,7 @@ namespace System.Reflection { - public struct ParameterModifier + public readonly struct ParameterModifier { private readonly bool[] _byRef; diff --git a/src/mscorlib/shared/System/Runtime/CompilerServices/ConfiguredValueTaskAwaitable.cs b/src/mscorlib/shared/System/Runtime/CompilerServices/ConfiguredValueTaskAwaitable.cs index f71067819b7e..b4efc737dea5 100644 --- a/src/mscorlib/shared/System/Runtime/CompilerServices/ConfiguredValueTaskAwaitable.cs +++ b/src/mscorlib/shared/System/Runtime/CompilerServices/ConfiguredValueTaskAwaitable.cs @@ -11,7 +11,7 @@ namespace System.Runtime.CompilerServices /// Provides an awaitable type that enables configured awaits on a . /// The type of the result produced. [StructLayout(LayoutKind.Auto)] - public struct ConfiguredValueTaskAwaitable + public readonly struct ConfiguredValueTaskAwaitable { /// The wrapped . private readonly ValueTask _value; diff --git a/src/mscorlib/shared/System/Runtime/Serialization/StreamingContext.cs b/src/mscorlib/shared/System/Runtime/Serialization/StreamingContext.cs index 4fe90cad8dae..cdcb1c335b7f 100644 --- a/src/mscorlib/shared/System/Runtime/Serialization/StreamingContext.cs +++ b/src/mscorlib/shared/System/Runtime/Serialization/StreamingContext.cs @@ -4,7 +4,7 @@ namespace System.Runtime.Serialization { - public struct StreamingContext + public readonly struct StreamingContext { private readonly object _additionalContext; private readonly StreamingContextStates _state; diff --git a/src/mscorlib/shared/System/Threading/Tasks/ValueTask.cs b/src/mscorlib/shared/System/Threading/Tasks/ValueTask.cs index 4ccf0f8a47d1..de9b016328cb 100644 --- a/src/mscorlib/shared/System/Threading/Tasks/ValueTask.cs +++ b/src/mscorlib/shared/System/Threading/Tasks/ValueTask.cs @@ -50,7 +50,7 @@ namespace System.Threading.Tasks /// [AsyncMethodBuilder(typeof(AsyncValueTaskMethodBuilder<>))] [StructLayout(LayoutKind.Auto)] - public struct ValueTask : IEquatable> + public readonly struct ValueTask : IEquatable> { /// The task to be used if the operation completed asynchronously or if it completed synchronously but non-successfully. internal readonly Task _task; diff --git a/src/mscorlib/src/System/ArraySegment.cs b/src/mscorlib/src/System/ArraySegment.cs index a96db8f9f709..251dee8a83e2 100644 --- a/src/mscorlib/src/System/ArraySegment.cs +++ b/src/mscorlib/src/System/ArraySegment.cs @@ -26,7 +26,7 @@ namespace System // (ie, users could assign a new value to the old location). [Serializable] [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")] - public struct ArraySegment : IList, IReadOnlyList + public readonly struct ArraySegment : IList, IReadOnlyList { // Do not replace the array allocation with Array.Empty. We don't want to have the overhead of // instantiating another generic type in addition to ArraySegment for new type parameters. diff --git a/src/mscorlib/src/System/DateTime.CoreCLR.cs b/src/mscorlib/src/System/DateTime.CoreCLR.cs index 4d36b9970a9c..84cda1d81311 100644 --- a/src/mscorlib/src/System/DateTime.CoreCLR.cs +++ b/src/mscorlib/src/System/DateTime.CoreCLR.cs @@ -6,7 +6,7 @@ namespace System { - public partial struct DateTime + public readonly partial struct DateTime { public static DateTime UtcNow { diff --git a/src/mscorlib/src/System/Nullable.cs b/src/mscorlib/src/System/Nullable.cs index f9ee9acdc70b..159453d0d4d3 100644 --- a/src/mscorlib/src/System/Nullable.cs +++ b/src/mscorlib/src/System/Nullable.cs @@ -23,10 +23,10 @@ namespace System [Serializable] [System.Runtime.Versioning.NonVersionable] // This only applies to field layout [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")] - public struct Nullable where T : struct + public readonly struct Nullable where T : struct { - private bool hasValue; // Do not rename (binary serialization) - internal T value; // Do not rename (binary serialization) + private readonly bool hasValue; // Do not rename (binary serialization) + internal readonly T value; // Do not rename (binary serialization) [System.Runtime.Versioning.NonVersionable] public Nullable(T value) diff --git a/src/mscorlib/src/System/Reflection/Emit/MethodBuilder.cs b/src/mscorlib/src/System/Reflection/Emit/MethodBuilder.cs index 928b2e3084f0..daa6d765b8f3 100644 --- a/src/mscorlib/src/System/Reflection/Emit/MethodBuilder.cs +++ b/src/mscorlib/src/System/Reflection/Emit/MethodBuilder.cs @@ -1103,7 +1103,7 @@ internal virtual void EmitLocalSymInfo(ISymbolWriter symWriter) /// Describes exception handler in a method body. /// [StructLayout(LayoutKind.Sequential)] - internal struct ExceptionHandler : IEquatable + internal readonly struct ExceptionHandler : IEquatable { // Keep in sync with unmanged structure. internal readonly int m_exceptionClass; diff --git a/src/mscorlib/src/System/Runtime/CompilerServices/TaskAwaiter.cs b/src/mscorlib/src/System/Runtime/CompilerServices/TaskAwaiter.cs index 5b2ac2822232..5fb43710753c 100644 --- a/src/mscorlib/src/System/Runtime/CompilerServices/TaskAwaiter.cs +++ b/src/mscorlib/src/System/Runtime/CompilerServices/TaskAwaiter.cs @@ -55,7 +55,7 @@ namespace System.Runtime.CompilerServices { /// Provides an awaiter for awaiting a . /// This type is intended for compiler use only. - public struct TaskAwaiter : ICriticalNotifyCompletion, ITaskAwaiter + public readonly struct TaskAwaiter : ICriticalNotifyCompletion, ITaskAwaiter { // WARNING: Unsafe.As is used to access the generic TaskAwaiter<> as TaskAwaiter. // Its layout must remain the same. @@ -320,7 +320,7 @@ private static Action OutputWaitEtwEvents(Task task, Action continuation) /// Provides an awaiter for awaiting a . /// This type is intended for compiler use only. - public struct TaskAwaiter : ICriticalNotifyCompletion, ITaskAwaiter + public readonly struct TaskAwaiter : ICriticalNotifyCompletion, ITaskAwaiter { // WARNING: Unsafe.As is used to access TaskAwaiter<> as the non-generic TaskAwaiter. // Its layout must remain the same. @@ -409,7 +409,7 @@ internal interface IConfiguredValueTaskAwaiter /// Provides an awaitable object that allows for configured awaits on . /// This type is intended for compiler use only. - public struct ConfiguredTaskAwaitable + public readonly struct ConfiguredTaskAwaitable { /// The task being awaited. private readonly ConfiguredTaskAwaitable.ConfiguredTaskAwaiter m_configuredTaskAwaiter; @@ -434,7 +434,7 @@ public ConfiguredTaskAwaitable.ConfiguredTaskAwaiter GetAwaiter() /// Provides an awaiter for a . /// This type is intended for compiler use only. - public struct ConfiguredTaskAwaiter : ICriticalNotifyCompletion, IConfiguredTaskAwaiter + public readonly struct ConfiguredTaskAwaiter : ICriticalNotifyCompletion, IConfiguredTaskAwaiter { // WARNING: Unsafe.As is used to access the generic ConfiguredTaskAwaiter as this. // Its layout must remain the same. @@ -500,7 +500,7 @@ public void GetResult() /// Provides an awaitable object that allows for configured awaits on . /// This type is intended for compiler use only. - public struct ConfiguredTaskAwaitable + public readonly struct ConfiguredTaskAwaitable { /// The underlying awaitable on whose logic this awaitable relies. private readonly ConfiguredTaskAwaitable.ConfiguredTaskAwaiter m_configuredTaskAwaiter; @@ -524,7 +524,7 @@ public ConfiguredTaskAwaitable.ConfiguredTaskAwaiter GetAwaiter() /// Provides an awaiter for a . /// This type is intended for compiler use only. - public struct ConfiguredTaskAwaiter : ICriticalNotifyCompletion, IConfiguredTaskAwaiter + public readonly struct ConfiguredTaskAwaiter : ICriticalNotifyCompletion, IConfiguredTaskAwaiter { // WARNING: Unsafe.As is used to access this as the non-generic ConfiguredTaskAwaiter. // Its layout must remain the same. diff --git a/src/mscorlib/src/System/Runtime/CompilerServices/YieldAwaitable.cs b/src/mscorlib/src/System/Runtime/CompilerServices/YieldAwaitable.cs index 8a7450bdb5d6..e2e43745a3e3 100644 --- a/src/mscorlib/src/System/Runtime/CompilerServices/YieldAwaitable.cs +++ b/src/mscorlib/src/System/Runtime/CompilerServices/YieldAwaitable.cs @@ -37,7 +37,7 @@ namespace System.Runtime.CompilerServices /// Provides an awaitable context for switching into a target environment. /// This type is intended for compiler use only. - public struct YieldAwaitable + public readonly struct YieldAwaitable { /// Gets an awaiter for this . /// An awaiter for this awaitable. @@ -46,7 +46,7 @@ public struct YieldAwaitable /// Provides an awaiter that switches into a target environment. /// This type is intended for compiler use only. - public struct YieldAwaiter : ICriticalNotifyCompletion + public readonly struct YieldAwaiter : ICriticalNotifyCompletion { /// Gets whether a yield is not required. /// This property is intended for compiler user rather than use directly in code. diff --git a/src/mscorlib/src/System/Threading/CancellationToken.cs b/src/mscorlib/src/System/Threading/CancellationToken.cs index 4d8688126726..86d5dcda7660 100644 --- a/src/mscorlib/src/System/Threading/CancellationToken.cs +++ b/src/mscorlib/src/System/Threading/CancellationToken.cs @@ -27,7 +27,7 @@ namespace System.Threading /// /// [DebuggerDisplay("IsCancellationRequested = {IsCancellationRequested}")] - public struct CancellationToken + public readonly struct CancellationToken { private readonly static Action s_actionToActionObjShunt = obj => ((Action)obj)(); diff --git a/src/mscorlib/src/System/Threading/CancellationTokenRegistration.cs b/src/mscorlib/src/System/Threading/CancellationTokenRegistration.cs index b3571d8f69bf..2b56bf79ed39 100644 --- a/src/mscorlib/src/System/Threading/CancellationTokenRegistration.cs +++ b/src/mscorlib/src/System/Threading/CancellationTokenRegistration.cs @@ -10,7 +10,7 @@ namespace System.Threading /// /// To unregister a callback, dispose the corresponding Registration instance. /// - public struct CancellationTokenRegistration : IEquatable, IDisposable + public readonly struct CancellationTokenRegistration : IEquatable, IDisposable { private readonly long _id; private readonly CancellationTokenSource.CallbackNode _node; diff --git a/src/mscorlib/src/System/TimeZoneInfo.TransitionTime.cs b/src/mscorlib/src/System/TimeZoneInfo.TransitionTime.cs index 81c0957f9a8a..b93794262cdd 100644 --- a/src/mscorlib/src/System/TimeZoneInfo.TransitionTime.cs +++ b/src/mscorlib/src/System/TimeZoneInfo.TransitionTime.cs @@ -9,7 +9,7 @@ namespace System public sealed partial class TimeZoneInfo { [Serializable] - public struct TransitionTime : IEquatable, ISerializable, IDeserializationCallback + public readonly struct TransitionTime : IEquatable, ISerializable, IDeserializationCallback { private readonly DateTime _timeOfDay; private readonly byte _month;