Skip to content

Commit

Permalink
Mark some Nullable<T> members as readonly (#1727)
Browse files Browse the repository at this point in the history
Value, HasValue, GetValueOrDefault
  • Loading branch information
ltrzesniewski authored and jkotas committed Jan 15, 2020
1 parent 4de18d6 commit 92025b2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/libraries/System.Private.CoreLib/src/System/Nullable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions src/libraries/System.Runtime/ref/System.Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1911,12 +1911,12 @@ public partial struct Nullable<T> 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; }
Expand Down

0 comments on commit 92025b2

Please sign in to comment.