From 86c2f66e4b3b3f56b222c163a7171e053c982bbf Mon Sep 17 00:00:00 2001 From: Lucas Trzesniewski Date: Tue, 14 Jan 2020 21:22:53 +0100 Subject: [PATCH] Mark some Nullable members as readonly Value, HasValue, GetValueOrDefault --- .../System.Private.CoreLib/src/System/Nullable.cs | 8 ++++---- src/libraries/System.Runtime/ref/System.Runtime.cs | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/Nullable.cs b/src/libraries/System.Private.CoreLib/src/System/Nullable.cs index b3ecf622128d14..223a446ae8eb60 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Nullable.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Nullable.cs @@ -26,13 +26,13 @@ public Nullable(T value) hasValue = true; } - public bool HasValue + public readonly bool HasValue { [NonVersionable] get => hasValue; } - public T Value + public readonly T Value { get { @@ -45,10 +45,10 @@ public T Value } [NonVersionable] - public T GetValueOrDefault() => value; + public readonly T GetValueOrDefault() => value; [NonVersionable] - public T GetValueOrDefault(T defaultValue) => + public readonly T GetValueOrDefault(T defaultValue) => hasValue ? value : defaultValue; public override bool Equals(object? other) diff --git a/src/libraries/System.Runtime/ref/System.Runtime.cs b/src/libraries/System.Runtime/ref/System.Runtime.cs index c09ae0d2c7eb4f..72ea52bb43893c 100644 --- a/src/libraries/System.Runtime/ref/System.Runtime.cs +++ b/src/libraries/System.Runtime/ref/System.Runtime.cs @@ -1911,12 +1911,12 @@ public partial struct Nullable where T : struct private T value; private int _dummyPrimitive; public Nullable(T value) { throw null; } - public bool HasValue { get { throw null; } } - public T Value { get { throw null; } } + public readonly bool HasValue { get { throw null; } } + public readonly T Value { get { throw null; } } public override bool Equals(object? other) { throw null; } public override int GetHashCode() { throw null; } - public T GetValueOrDefault() { throw null; } - public T GetValueOrDefault(T defaultValue) { throw null; } + public readonly T GetValueOrDefault() { throw null; } + public readonly T GetValueOrDefault(T defaultValue) { throw null; } public static explicit operator T (T? value) { throw null; } public static implicit operator T? (T value) { throw null; } public override string? ToString() { throw null; }