In a few cases (e.g. nullable), I added readonly to fields in order to allow readonly on the type.
// and IReadOnlyDictionary<TKey, TValue>.
[Serializable]
[System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public struct KeyValuePair<TKey, TValue>
+ public readonly struct KeyValuePair<TKey, TValue>
{
- 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)
{
[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<DateTime>, IEquatable<DateTime>, ISerializable
+ public readonly partial struct DateTime : IComparable, IFormattable, IConvertible, IComparable<DateTime>, IEquatable<DateTime>, ISerializable
{
// Number of 100ns ticks per time unit
private const long TicksPerMillisecond = 10000;
// 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
-using System;
+using System;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Diagnostics;
#else
internal
#endif
- unsafe struct PropertyValue
+ unsafe readonly struct PropertyValue
{
/// <summary>
/// Union of well-known value types, to avoid boxing those types.
}
// Value type version of DaylightTime
- internal struct DaylightTimeStruct
+ internal readonly struct DaylightTimeStruct
{
public DaylightTimeStruct(DateTime start, DateTime end, TimeSpan delta)
{
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,
namespace System.Reflection
{
- public struct ParameterModifier
+ public readonly struct ParameterModifier
{
private readonly bool[] _byRef;
/// <summary>Provides an awaitable type that enables configured awaits on a <see cref="ValueTask{TResult}"/>.</summary>
/// <typeparam name="TResult">The type of the result produced.</typeparam>
[StructLayout(LayoutKind.Auto)]
- public struct ConfiguredValueTaskAwaitable<TResult>
+ public readonly struct ConfiguredValueTaskAwaitable<TResult>
{
/// <summary>The wrapped <see cref="ValueTask{TResult}"/>.</summary>
private readonly ValueTask<TResult> _value;
namespace System.Runtime.Serialization
{
- public struct StreamingContext
+ public readonly struct StreamingContext
{
private readonly object _additionalContext;
private readonly StreamingContextStates _state;
/// </remarks>
[AsyncMethodBuilder(typeof(AsyncValueTaskMethodBuilder<>))]
[StructLayout(LayoutKind.Auto)]
- public struct ValueTask<TResult> : IEquatable<ValueTask<TResult>>
+ public readonly struct ValueTask<TResult> : IEquatable<ValueTask<TResult>>
{
/// <summary>The task to be used if the operation completed asynchronously or if it completed synchronously but non-successfully.</summary>
internal readonly Task<TResult> _task;
// (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<T> : IList<T>, IReadOnlyList<T>
+ public readonly struct ArraySegment<T> : IList<T>, IReadOnlyList<T>
{
// 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<T> for new type parameters.
namespace System
{
- public partial struct DateTime
+ public readonly partial struct DateTime
{
public static DateTime UtcNow
{
[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<T> where T : struct
+ public readonly struct Nullable<T> 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)
/// Describes exception handler in a method body.
/// </summary>
[StructLayout(LayoutKind.Sequential)]
- internal struct ExceptionHandler : IEquatable<ExceptionHandler>
+ internal readonly struct ExceptionHandler : IEquatable<ExceptionHandler>
{
// Keep in sync with unmanged structure.
internal readonly int m_exceptionClass;
{
/// <summary>Provides an awaiter for awaiting a <see cref="System.Threading.Tasks.Task"/>.</summary>
/// <remarks>This type is intended for compiler use only.</remarks>
- 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.
/// <summary>Provides an awaiter for awaiting a <see cref="System.Threading.Tasks.Task{TResult}"/>.</summary>
/// <remarks>This type is intended for compiler use only.</remarks>
- public struct TaskAwaiter<TResult> : ICriticalNotifyCompletion, ITaskAwaiter
+ public readonly struct TaskAwaiter<TResult> : ICriticalNotifyCompletion, ITaskAwaiter
{
// WARNING: Unsafe.As is used to access TaskAwaiter<> as the non-generic TaskAwaiter.
// Its layout must remain the same.
/// <summary>Provides an awaitable object that allows for configured awaits on <see cref="System.Threading.Tasks.Task"/>.</summary>
/// <remarks>This type is intended for compiler use only.</remarks>
- public struct ConfiguredTaskAwaitable
+ public readonly struct ConfiguredTaskAwaitable
{
/// <summary>The task being awaited.</summary>
private readonly ConfiguredTaskAwaitable.ConfiguredTaskAwaiter m_configuredTaskAwaiter;
/// <summary>Provides an awaiter for a <see cref="ConfiguredTaskAwaitable"/>.</summary>
/// <remarks>This type is intended for compiler use only.</remarks>
- 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.
/// <summary>Provides an awaitable object that allows for configured awaits on <see cref="System.Threading.Tasks.Task{TResult}"/>.</summary>
/// <remarks>This type is intended for compiler use only.</remarks>
- public struct ConfiguredTaskAwaitable<TResult>
+ public readonly struct ConfiguredTaskAwaitable<TResult>
{
/// <summary>The underlying awaitable on whose logic this awaitable relies.</summary>
private readonly ConfiguredTaskAwaitable<TResult>.ConfiguredTaskAwaiter m_configuredTaskAwaiter;
/// <summary>Provides an awaiter for a <see cref="ConfiguredTaskAwaitable{TResult}"/>.</summary>
/// <remarks>This type is intended for compiler use only.</remarks>
- 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.
/// <summary>Provides an awaitable context for switching into a target environment.</summary>
/// <remarks>This type is intended for compiler use only.</remarks>
- public struct YieldAwaitable
+ public readonly struct YieldAwaitable
{
/// <summary>Gets an awaiter for this <see cref="YieldAwaitable"/>.</summary>
/// <returns>An awaiter for this awaitable.</returns>
/// <summary>Provides an awaiter that switches into a target environment.</summary>
/// <remarks>This type is intended for compiler use only.</remarks>
- public struct YieldAwaiter : ICriticalNotifyCompletion
+ public readonly struct YieldAwaiter : ICriticalNotifyCompletion
{
/// <summary>Gets whether a yield is not required.</summary>
/// <remarks>This property is intended for compiler user rather than use directly in code.</remarks>
/// </para>
/// </remarks>
[DebuggerDisplay("IsCancellationRequested = {IsCancellationRequested}")]
- public struct CancellationToken
+ public readonly struct CancellationToken
{
private readonly static Action<object> s_actionToActionObjShunt = obj => ((Action)obj)();
/// <remarks>
/// To unregister a callback, dispose the corresponding Registration instance.
/// </remarks>
- public struct CancellationTokenRegistration : IEquatable<CancellationTokenRegistration>, IDisposable
+ public readonly struct CancellationTokenRegistration : IEquatable<CancellationTokenRegistration>, IDisposable
{
private readonly long _id;
private readonly CancellationTokenSource.CallbackNode _node;
public sealed partial class TimeZoneInfo
{
[Serializable]
- public struct TransitionTime : IEquatable<TransitionTime>, ISerializable, IDeserializationCallback
+ public readonly struct TransitionTime : IEquatable<TransitionTime>, ISerializable, IDeserializationCallback
{
private readonly DateTime _timeOfDay;
private readonly byte _month;