Skip to content

Commit af2acbc

Browse files
committed
Make mutable struct members readonly.
Signed-off-by: Bradley Grainger <[email protected]>
1 parent 9d2deba commit af2acbc

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/MySqlConnector/MySql.Data.Types/MySqlDateTime.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public MySqlDateTime(MySqlDateTime other)
3131
Microsecond = other.Microsecond;
3232
}
3333

34-
public bool IsValidDateTime => Year != 0 && Month != 0 && Day != 0;
34+
public readonly bool IsValidDateTime => Year != 0 && Month != 0 && Day != 0;
3535

3636
public int Year { get; set; }
3737
public int Month { get; set; }
@@ -47,15 +47,15 @@ public int Millisecond
4747
set => Microsecond = value * 1000;
4848
}
4949

50-
public DateTime GetDateTime() =>
50+
public readonly DateTime GetDateTime() =>
5151
!IsValidDateTime ? throw new MySqlConversionException("Cannot convert MySqlDateTime to DateTime when IsValidDateTime is false.") :
5252
new DateTime(Year, Month, Day, Hour, Minute, Second, DateTimeKind.Unspecified).AddTicks(Microsecond * 10);
5353

54-
public override string ToString() => IsValidDateTime ? GetDateTime().ToString() : "0000-00-00";
54+
public readonly override string ToString() => IsValidDateTime ? GetDateTime().ToString() : "0000-00-00";
5555

5656
public static explicit operator DateTime(MySqlDateTime val) => !val.IsValidDateTime ? DateTime.MinValue : val.GetDateTime();
5757

58-
int IComparable.CompareTo(object? obj)
58+
readonly int IComparable.CompareTo(object? obj)
5959
{
6060
if (!(obj is MySqlDateTime other))
6161
throw new ArgumentException("CompareTo can only be called with another MySqlDateTime", nameof(obj));

0 commit comments

Comments
 (0)