diff --git a/src/System.Private.CoreLib/shared/System/Globalization/TimeSpanParse.cs b/src/System.Private.CoreLib/shared/System/Globalization/TimeSpanParse.cs index 3f642e85e..1bf81742a 100644 --- a/src/System.Private.CoreLib/shared/System/Globalization/TimeSpanParse.cs +++ b/src/System.Private.CoreLib/shared/System/Globalization/TimeSpanParse.cs @@ -804,7 +804,7 @@ namespace System.Globalization } } - result.parsedTimeSpan._ticks = ticks; + result.parsedTimeSpan = new TimeSpan(ticks); return true; } @@ -932,7 +932,7 @@ namespace System.Globalization } } - result.parsedTimeSpan._ticks = ticks; + result.parsedTimeSpan = new TimeSpan(ticks); return true; } @@ -1058,7 +1058,7 @@ namespace System.Globalization } } - result.parsedTimeSpan._ticks = ticks; + result.parsedTimeSpan = new TimeSpan(ticks); return true; } @@ -1130,7 +1130,7 @@ namespace System.Globalization } } - result.parsedTimeSpan._ticks = ticks; + result.parsedTimeSpan = new TimeSpan(ticks); return true; } @@ -1200,7 +1200,7 @@ namespace System.Globalization } } - result.parsedTimeSpan._ticks = ticks; + result.parsedTimeSpan = new TimeSpan(ticks); return true; } @@ -1399,7 +1399,7 @@ namespace System.Globalization ticks = -ticks; } - result.parsedTimeSpan._ticks = ticks; + result.parsedTimeSpan = new TimeSpan(ticks); return true; } else @@ -1494,7 +1494,7 @@ namespace System.Globalization internal bool TryParse(ReadOnlySpan input, ref TimeSpanResult result) { - result.parsedTimeSpan._ticks = 0; + result.parsedTimeSpan = default; _str = input; _len = input.Length; @@ -1563,7 +1563,7 @@ namespace System.Globalization return result.SetBadTimeSpanFailure(); } - result.parsedTimeSpan._ticks = time; + result.parsedTimeSpan = new TimeSpan(time); return true; } diff --git a/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/HandleRef.cs b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/HandleRef.cs index 64d055313..c81a70199 100644 --- a/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/HandleRef.cs +++ b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/HandleRef.cs @@ -4,12 +4,12 @@ namespace System.Runtime.InteropServices { - public struct HandleRef + public readonly struct HandleRef { // ! Do not add or rearrange fields as the EE depends on this layout. //------------------------------------------------------------------ - private object _wrapper; - private IntPtr _handle; + private readonly object _wrapper; + private readonly IntPtr _handle; //------------------------------------------------------------------ public HandleRef(object wrapper, IntPtr handle) diff --git a/src/System.Private.CoreLib/shared/System/Runtime/Serialization/SerializationInfoEnumerator.cs b/src/System.Private.CoreLib/shared/System/Runtime/Serialization/SerializationInfoEnumerator.cs index 639951073..ba84e6542 100644 --- a/src/System.Private.CoreLib/shared/System/Runtime/Serialization/SerializationInfoEnumerator.cs +++ b/src/System.Private.CoreLib/shared/System/Runtime/Serialization/SerializationInfoEnumerator.cs @@ -7,11 +7,11 @@ using System.Diagnostics; namespace System.Runtime.Serialization { - public struct SerializationEntry + public readonly struct SerializationEntry { - private string _name; - private object _value; - private Type _type; + private readonly string _name; + private readonly object _value; + private readonly Type _type; internal SerializationEntry(string entryName, object entryValue, Type entryType) { diff --git a/src/System.Private.CoreLib/shared/System/SpanHelpers.BinarySearch.cs b/src/System.Private.CoreLib/shared/System/SpanHelpers.BinarySearch.cs index a81a5d341..2aec70409 100644 --- a/src/System.Private.CoreLib/shared/System/SpanHelpers.BinarySearch.cs +++ b/src/System.Private.CoreLib/shared/System/SpanHelpers.BinarySearch.cs @@ -62,11 +62,11 @@ namespace System } // Helper to allow sharing all code via IComparable inlineable - internal struct ComparerComparable : IComparable + internal readonly struct ComparerComparable : IComparable where TComparer : IComparer { - readonly T _value; - readonly TComparer _comparer; + private readonly T _value; + private readonly TComparer _comparer; public ComparerComparable(T value, TComparer comparer) { diff --git a/src/System.Private.CoreLib/shared/System/Threading/AsyncLocal.cs b/src/System.Private.CoreLib/shared/System/Threading/AsyncLocal.cs index 84bbd173c..12d650243 100644 --- a/src/System.Private.CoreLib/shared/System/Threading/AsyncLocal.cs +++ b/src/System.Private.CoreLib/shared/System/Threading/AsyncLocal.cs @@ -86,19 +86,18 @@ namespace System.Threading void OnValueChanged(object previousValue, object currentValue, bool contextChanged); } - public struct AsyncLocalValueChangedArgs + public readonly struct AsyncLocalValueChangedArgs { - public T PreviousValue { get; private set; } - public T CurrentValue { get; private set; } + public T PreviousValue { get; } + public T CurrentValue { get; } // // If the value changed because we changed to a different ExecutionContext, this is true. If it changed // because someone set the Value property, this is false. // - public bool ThreadContextChanged { get; private set; } + public bool ThreadContextChanged { get; } internal AsyncLocalValueChangedArgs(T previousValue, T currentValue, bool contextChanged) - : this() { PreviousValue = previousValue; CurrentValue = currentValue; diff --git a/src/System.Private.CoreLib/shared/System/TimeSpan.cs b/src/System.Private.CoreLib/shared/System/TimeSpan.cs index 1b94c9f15..10bdb331b 100644 --- a/src/System.Private.CoreLib/shared/System/TimeSpan.cs +++ b/src/System.Private.CoreLib/shared/System/TimeSpan.cs @@ -28,7 +28,7 @@ namespace System // an appropriate custom ILMarshaler to keep WInRT interop scenarios enabled. // [Serializable] - public struct TimeSpan : IComparable, IComparable, IEquatable, IFormattable, ISpanFormattable + public readonly struct TimeSpan : IComparable, IComparable, IEquatable, IFormattable, ISpanFormattable { public const long TicksPerMillisecond = 10000; private const double MillisecondsPerTick = 1.0 / TicksPerMillisecond; @@ -65,7 +65,7 @@ namespace System // 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) {