Skip to content
This repository was archived by the owner on Aug 8, 2024. It is now read-only.

Make primitive types readonly #260

Merged
merged 1 commit into from
Feb 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/Common/src/CoreLib/System/DateTimeOffset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace System
#if !MONO
[System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
#endif
public struct DateTimeOffset : IComparable, IFormattable, IComparable<DateTimeOffset>, IEquatable<DateTimeOffset>, ISerializable, IDeserializationCallback, ISpanFormattable
public readonly struct DateTimeOffset : IComparable, IFormattable, IComparable<DateTimeOffset>, IEquatable<DateTimeOffset>, ISerializable, IDeserializationCallback, ISpanFormattable
{
// Constants
internal const Int64 MaxOffset = TimeSpan.TicksPerHour * 14;
Expand All @@ -51,8 +51,8 @@ public struct DateTimeOffset : IComparable, IFormattable, IComparable<DateTimeOf
public static readonly DateTimeOffset UnixEpoch = new DateTimeOffset(DateTime.UnixEpochTicks, TimeSpan.Zero);

// Instance Fields
private DateTime _dateTime;
private Int16 _offsetMinutes;
private readonly DateTime _dateTime;
private readonly Int16 _offsetMinutes;

// Constructors

Expand Down Expand Up @@ -555,8 +555,8 @@ void IDeserializationCallback.OnDeserialization(Object sender)
{
try
{
_offsetMinutes = ValidateOffset(Offset);
_dateTime = ValidateDate(ClockDateTime, Offset);
ValidateOffset(Offset);
ValidateDate(ClockDateTime, Offset);
}
catch (ArgumentException e)
{
Expand Down
6 changes: 3 additions & 3 deletions src/Common/src/CoreLib/System/Double.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ namespace System
#if !MONO
[TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
#endif
public struct Double : IComparable, IConvertible, IFormattable, IComparable<Double>, IEquatable<Double>, ISpanFormattable
public readonly struct Double : IComparable, IConvertible, IFormattable, IComparable<Double>, IEquatable<Double>, ISpanFormattable
{
private double m_value; // Do not rename (binary serialization)
private readonly double m_value; // Do not rename (binary serialization)

//
// Public Constants
Expand Down Expand Up @@ -228,7 +228,7 @@ public bool Equals(Double obj)
[MethodImpl(MethodImplOptions.AggressiveInlining)] // 64-bit constants make the IL unusually large that makes the inliner to reject the method
public override int GetHashCode()
{
var bits = Unsafe.As<double, long>(ref m_value);
var bits = BitConverter.DoubleToInt64Bits(m_value);

// Optimized check for IsNan() || IsZero()
if (((bits - 1) & 0x7FFFFFFFFFFFFFFF) >= 0x7FF0000000000000)
Expand Down
16 changes: 8 additions & 8 deletions src/Common/src/CoreLib/System/Globalization/TimeSpanParse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ private static bool ProcessTerminal_DHMSF(ref TimeSpanRawInfo raw, TimeSpanStand
}
}

result.parsedTimeSpan._ticks = ticks;
result.parsedTimeSpan = new TimeSpan(ticks);
return true;
}

Expand Down Expand Up @@ -894,7 +894,7 @@ private static bool ProcessTerminal_HMS_F_D(ref TimeSpanRawInfo raw, TimeSpanSta
}
}

result.parsedTimeSpan._ticks = ticks;
result.parsedTimeSpan = new TimeSpan(ticks);
return true;
}

Expand Down Expand Up @@ -1020,7 +1020,7 @@ private static bool ProcessTerminal_HM_S_D(ref TimeSpanRawInfo raw, TimeSpanStan
}
}

result.parsedTimeSpan._ticks = ticks;
result.parsedTimeSpan = new TimeSpan(ticks);
return true;
}

Expand Down Expand Up @@ -1092,7 +1092,7 @@ private static bool ProcessTerminal_HM(ref TimeSpanRawInfo raw, TimeSpanStandard
}
}

result.parsedTimeSpan._ticks = ticks;
result.parsedTimeSpan = new TimeSpan(ticks);
return true;
}

Expand Down Expand Up @@ -1162,7 +1162,7 @@ private static bool ProcessTerminal_D(ref TimeSpanRawInfo raw, TimeSpanStandardS
}
}

result.parsedTimeSpan._ticks = ticks;
result.parsedTimeSpan = new TimeSpan(ticks);
return true;
}

Expand Down Expand Up @@ -1361,7 +1361,7 @@ private static bool TryParseByFormat(ReadOnlySpan<char> input, ReadOnlySpan<char
ticks = -ticks;
}

result.parsedTimeSpan._ticks = ticks;
result.parsedTimeSpan = new TimeSpan(ticks);
return true;
}
else
Expand Down Expand Up @@ -1456,7 +1456,7 @@ internal char NextNonDigit()

internal bool TryParse(ReadOnlySpan<char> input, ref TimeSpanResult result)
{
result.parsedTimeSpan._ticks = 0;
result.parsedTimeSpan = default;

_str = input;
_len = input.Length;
Expand Down Expand Up @@ -1525,7 +1525,7 @@ internal bool TryParse(ReadOnlySpan<char> input, ref TimeSpanResult result)
return result.SetFailure(ParseFailureKind.Format, nameof(SR.Format_BadTimeSpan));
}

result.parsedTimeSpan._ticks = time;
result.parsedTimeSpan = new TimeSpan(time);
return true;
}

Expand Down
6 changes: 3 additions & 3 deletions src/Common/src/CoreLib/System/Single.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ namespace System
#if !MONO
[TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
#endif
public struct Single : IComparable, IConvertible, IFormattable, IComparable<Single>, IEquatable<Single>, ISpanFormattable
public readonly struct Single : IComparable, IConvertible, IFormattable, IComparable<Single>, IEquatable<Single>, ISpanFormattable
{
private float m_value; // Do not rename (binary serialization)
private readonly float m_value; // Do not rename (binary serialization)

//
// Public constants
Expand Down Expand Up @@ -219,7 +219,7 @@ public bool Equals(Single obj)

public override int GetHashCode()
{
var bits = Unsafe.As<float, int>(ref m_value);
var bits = BitConverter.SingleToInt32Bits(m_value);

// Optimized check for IsNan() || IsZero()
if (((bits - 1) & 0x7FFFFFFF) >= 0x7F800000)
Expand Down
4 changes: 2 additions & 2 deletions src/Common/src/CoreLib/System/TimeSpan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace System
// an appropriate custom ILMarshaler to keep WInRT interop scenarios enabled.
//
[Serializable]
public struct TimeSpan : IComparable, IComparable<TimeSpan>, IEquatable<TimeSpan>, IFormattable, ISpanFormattable
public readonly struct TimeSpan : IComparable, IComparable<TimeSpan>, IEquatable<TimeSpan>, IFormattable, ISpanFormattable
{
public const long TicksPerMillisecond = 10000;
private const double MillisecondsPerTick = 1.0 / TicksPerMillisecond;
Expand Down Expand Up @@ -65,7 +65,7 @@ public struct TimeSpan : IComparable, IComparable<TimeSpan>, IEquatable<TimeSpan

// internal so that DateTime doesn't have to call an extra get
// method for some arithmetic operations.
internal long _ticks; // Do not rename (binary serialization)
internal readonly long _ticks; // Do not rename (binary serialization)

public TimeSpan(long ticks)
{
Expand Down
2 changes: 1 addition & 1 deletion src/System.Data.Common/src/System/Data/DataSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace System.Data
[XmlRoot(nameof(DataSet))]
#if !MONO
[System.Runtime.CompilerServices.TypeForwardedFrom("System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
else
#else
[System.ComponentModel.ToolboxItemAttribute("Microsoft.VSDesigner.Data.VS.DataSetToolboxItem, Microsoft.VSDesigner, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
#endif
public class DataSet : MarshalByValueComponent, IListSource, IXmlSerializable, ISupportInitializeNotification, ISerializable
Expand Down