You've already forked linux-packaging-mono
Imported Upstream version 6.4.0.137
Former-commit-id: 943baa9f16a098c33e129777827f3a9d20da00d6
This commit is contained in:
parent
e9207cf623
commit
ef583813eb
@@ -199,6 +199,7 @@
|
||||
<Compile Include="$(MSBuildThisFileDirectory)System\IEquatable.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)System\IFormatProvider.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)System\IFormattable.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)System\Index.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)System\IndexOutOfRangeException.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)System\InsufficientExecutionStackException.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)System\InvalidCastException.cs" />
|
||||
@@ -273,6 +274,7 @@
|
||||
<Compile Include="$(MSBuildThisFileDirectory)System\PlatformNotSupportedException.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)System\Progress.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)System\Random.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)System\Range.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)System\RankException.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)System\ReadOnlySpan.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)System\ReadOnlySpan.Fast.cs" />
|
||||
|
||||
@@ -21,12 +21,12 @@ namespace System
|
||||
#if !MONO
|
||||
[TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
|
||||
#endif
|
||||
public struct Boolean : IComparable, IConvertible, IComparable<Boolean>, IEquatable<Boolean>
|
||||
public readonly struct Boolean : IComparable, IConvertible, IComparable<Boolean>, IEquatable<Boolean>
|
||||
{
|
||||
//
|
||||
// Member Variables
|
||||
//
|
||||
private bool m_value; // Do not rename (binary serialization)
|
||||
private readonly bool m_value; // Do not rename (binary serialization)
|
||||
|
||||
// The true value.
|
||||
//
|
||||
|
||||
@@ -14,9 +14,9 @@ namespace System
|
||||
#if !MONO
|
||||
[TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
|
||||
#endif
|
||||
public struct Byte : IComparable, IConvertible, IFormattable, IComparable<Byte>, IEquatable<Byte>, ISpanFormattable
|
||||
public readonly struct Byte : IComparable, IConvertible, IFormattable, IComparable<Byte>, IEquatable<Byte>, ISpanFormattable
|
||||
{
|
||||
private byte m_value; // Do not rename (binary serialization)
|
||||
private readonly byte m_value; // Do not rename (binary serialization)
|
||||
|
||||
// The maximum value that a Byte may represent: 255.
|
||||
public const byte MaxValue = (byte)0xFF;
|
||||
|
||||
@@ -23,12 +23,12 @@ namespace System
|
||||
#if !MONO
|
||||
[System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
|
||||
#endif
|
||||
public struct Char : IComparable, IComparable<Char>, IEquatable<Char>, IConvertible
|
||||
public readonly struct Char : IComparable, IComparable<Char>, IEquatable<Char>, IConvertible
|
||||
{
|
||||
//
|
||||
// Member Variables
|
||||
//
|
||||
private char m_value; // Do not rename (binary serialization)
|
||||
private readonly char m_value; // Do not rename (binary serialization)
|
||||
|
||||
//
|
||||
// Public Constants
|
||||
|
||||
@@ -16,8 +16,6 @@ namespace System.Collections.ObjectModel
|
||||
public class Collection<T> : IList<T>, IList, IReadOnlyList<T>
|
||||
{
|
||||
private IList<T> items; // Do not rename (binary serialization)
|
||||
[NonSerialized]
|
||||
private Object _syncRoot;
|
||||
|
||||
public Collection()
|
||||
{
|
||||
@@ -53,7 +51,7 @@ namespace System.Collections.ObjectModel
|
||||
ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_ReadOnlyCollection);
|
||||
}
|
||||
|
||||
if (index < 0 || index >= items.Count)
|
||||
if ((uint)index >= (uint)items.Count)
|
||||
{
|
||||
ThrowHelper.ThrowArgumentOutOfRange_IndexException();
|
||||
}
|
||||
@@ -110,9 +108,9 @@ namespace System.Collections.ObjectModel
|
||||
ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_ReadOnlyCollection);
|
||||
}
|
||||
|
||||
if (index < 0 || index > items.Count)
|
||||
if ((uint)index > (uint)items.Count)
|
||||
{
|
||||
ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_ListInsert);
|
||||
ThrowHelper.ThrowArgumentOutOfRange_IndexException();
|
||||
}
|
||||
|
||||
InsertItem(index, item);
|
||||
@@ -138,7 +136,7 @@ namespace System.Collections.ObjectModel
|
||||
ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_ReadOnlyCollection);
|
||||
}
|
||||
|
||||
if (index < 0 || index >= items.Count)
|
||||
if ((uint)index >= (uint)items.Count)
|
||||
{
|
||||
ThrowHelper.ThrowArgumentOutOfRange_IndexException();
|
||||
}
|
||||
@@ -188,19 +186,7 @@ namespace System.Collections.ObjectModel
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_syncRoot == null)
|
||||
{
|
||||
ICollection c = items as ICollection;
|
||||
if (c != null)
|
||||
{
|
||||
_syncRoot = c.SyncRoot;
|
||||
}
|
||||
else
|
||||
{
|
||||
System.Threading.Interlocked.CompareExchange<Object>(ref _syncRoot, new Object(), null);
|
||||
}
|
||||
}
|
||||
return _syncRoot;
|
||||
return (items is ICollection coll) ? coll.SyncRoot : this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -231,8 +217,7 @@ namespace System.Collections.ObjectModel
|
||||
ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_ArrayPlusOffTooSmall);
|
||||
}
|
||||
|
||||
T[] tArray = array as T[];
|
||||
if (tArray != null)
|
||||
if (array is T[] tArray)
|
||||
{
|
||||
items.CopyTo(tArray, index);
|
||||
}
|
||||
@@ -310,8 +295,7 @@ namespace System.Collections.ObjectModel
|
||||
// readonly collections are fixed size, if our internal item
|
||||
// collection does not implement IList. Note that Array implements
|
||||
// IList, and therefore T[] and U[] will be fixed-size.
|
||||
IList list = items as IList;
|
||||
if (list != null)
|
||||
if (items is IList list)
|
||||
{
|
||||
return list.IsFixedSize;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
@@ -51,8 +51,8 @@ namespace System
|
||||
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
|
||||
|
||||
@@ -555,8 +555,8 @@ namespace System
|
||||
{
|
||||
try
|
||||
{
|
||||
_offsetMinutes = ValidateOffset(Offset);
|
||||
_dateTime = ValidateDate(ClockDateTime, Offset);
|
||||
ValidateOffset(Offset);
|
||||
ValidateDate(ClockDateTime, Offset);
|
||||
}
|
||||
catch (ArgumentException e)
|
||||
{
|
||||
|
||||
@@ -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
|
||||
@@ -228,7 +228,7 @@ namespace System
|
||||
[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)
|
||||
|
||||
@@ -461,8 +461,8 @@ namespace System
|
||||
}
|
||||
|
||||
// This is a flag to indicate if we are format the dates using Hebrew calendar.
|
||||
bool isHebrewCalendar = ((CalendarId)cal.ID == CalendarId.HEBREW);
|
||||
bool isJapaneseCalendar = ((CalendarId)cal.ID == CalendarId.JAPAN);
|
||||
bool isHebrewCalendar = !GlobalizationMode.Invariant && ((CalendarId)cal.ID == CalendarId.HEBREW);
|
||||
bool isJapaneseCalendar = !GlobalizationMode.Invariant && ((CalendarId)cal.ID == CalendarId.JAPAN);
|
||||
// This is a flag to indicate if we are formating hour/minute/second only.
|
||||
bool bTimeOnly = true;
|
||||
|
||||
@@ -584,7 +584,7 @@ namespace System
|
||||
if (tokenLen <= 2)
|
||||
{
|
||||
int day = cal.GetDayOfMonth(dateTime);
|
||||
if (isHebrewCalendar)
|
||||
if (isHebrewCalendar && !GlobalizationMode.Invariant)
|
||||
{
|
||||
// For Hebrew calendar, we need to convert numbers to Hebrew text for yyyy, MM, and dd values.
|
||||
HebrewFormatDigits(result, day);
|
||||
@@ -612,7 +612,7 @@ namespace System
|
||||
int month = cal.GetMonth(dateTime);
|
||||
if (tokenLen <= 2)
|
||||
{
|
||||
if (isHebrewCalendar)
|
||||
if (isHebrewCalendar && !GlobalizationMode.Invariant)
|
||||
{
|
||||
// For Hebrew calendar, we need to convert numbers to Hebrew text for yyyy, MM, and dd values.
|
||||
HebrewFormatDigits(result, month);
|
||||
@@ -624,7 +624,7 @@ namespace System
|
||||
}
|
||||
else
|
||||
{
|
||||
if (isHebrewCalendar)
|
||||
if (isHebrewCalendar && !GlobalizationMode.Invariant)
|
||||
{
|
||||
result.Append(FormatHebrewMonthName(dateTime, month, tokenLen, dtfi));
|
||||
}
|
||||
@@ -670,7 +670,7 @@ namespace System
|
||||
{
|
||||
FormatDigits(result, year, tokenLen <= 2 ? tokenLen : 2);
|
||||
}
|
||||
else if ((CalendarId)cal.ID == CalendarId.HEBREW)
|
||||
else if (isHebrewCalendar && !GlobalizationMode.Invariant)
|
||||
{
|
||||
HebrewFormatDigits(result, year);
|
||||
}
|
||||
|
||||
@@ -1 +1 @@
|
||||
314120f3cfcb0de6415530f7dca52ec5e4bc7a90
|
||||
07a3c46e17aed107177859626d0ca573363b0821
|
||||
@@ -1 +1 @@
|
||||
0dccb4fcb01a2b425dc04ac71bbc7969ad7c2326
|
||||
63f3e793e95c338fe7b364780a6492b962cb5f5b
|
||||
@@ -766,7 +766,7 @@ namespace System.Globalization
|
||||
}
|
||||
}
|
||||
|
||||
result.parsedTimeSpan._ticks = ticks;
|
||||
result.parsedTimeSpan = new TimeSpan(ticks);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -894,7 +894,7 @@ namespace System.Globalization
|
||||
}
|
||||
}
|
||||
|
||||
result.parsedTimeSpan._ticks = ticks;
|
||||
result.parsedTimeSpan = new TimeSpan(ticks);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1020,7 +1020,7 @@ namespace System.Globalization
|
||||
}
|
||||
}
|
||||
|
||||
result.parsedTimeSpan._ticks = ticks;
|
||||
result.parsedTimeSpan = new TimeSpan(ticks);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1092,7 +1092,7 @@ namespace System.Globalization
|
||||
}
|
||||
}
|
||||
|
||||
result.parsedTimeSpan._ticks = ticks;
|
||||
result.parsedTimeSpan = new TimeSpan(ticks);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1162,7 +1162,7 @@ namespace System.Globalization
|
||||
}
|
||||
}
|
||||
|
||||
result.parsedTimeSpan._ticks = ticks;
|
||||
result.parsedTimeSpan = new TimeSpan(ticks);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1361,7 +1361,7 @@ namespace System.Globalization
|
||||
ticks = -ticks;
|
||||
}
|
||||
|
||||
result.parsedTimeSpan._ticks = ticks;
|
||||
result.parsedTimeSpan = new TimeSpan(ticks);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
@@ -1456,7 +1456,7 @@ namespace System.Globalization
|
||||
|
||||
internal bool TryParse(ReadOnlySpan<char> input, ref TimeSpanResult result)
|
||||
{
|
||||
result.parsedTimeSpan._ticks = 0;
|
||||
result.parsedTimeSpan = default;
|
||||
|
||||
_str = input;
|
||||
_len = input.Length;
|
||||
@@ -1525,7 +1525,7 @@ namespace System.Globalization
|
||||
return result.SetFailure(ParseFailureKind.Format, nameof(SR.Format_BadTimeSpan));
|
||||
}
|
||||
|
||||
result.parsedTimeSpan._ticks = time;
|
||||
result.parsedTimeSpan = new TimeSpan(time);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ namespace System
|
||||
{
|
||||
internal const int COR_E_ABANDONEDMUTEX = unchecked((int)0x8013152D);
|
||||
internal const int COR_E_AMBIGUOUSMATCH = unchecked((int)0x8000211D);
|
||||
internal const int COR_E_AMBIGUOUSIMPLEMENTATION = unchecked((int)0x8013106A);
|
||||
internal const int COR_E_APPDOMAINUNLOADED = unchecked((int)0x80131014);
|
||||
internal const int COR_E_APPLICATION = unchecked((int)0x80131600);
|
||||
internal const int COR_E_ARGUMENT = unchecked((int)0x80070057);
|
||||
|
||||
@@ -232,6 +232,68 @@ namespace System.IO
|
||||
}
|
||||
}
|
||||
|
||||
#if MONO // Copied from CoreFX-master (NS2.1)
|
||||
public override ValueTask DisposeAsync()
|
||||
{
|
||||
#if __MonoCS__
|
||||
return GetType() != typeof(StreamWriter) ? base.DisposeAsync() : new ValueTask(DisposeAsyncCore());
|
||||
#else
|
||||
return GetType() != typeof(StreamWriter) ? base.DisposeAsync() : DisposeAsyncCore();
|
||||
#endif
|
||||
}
|
||||
|
||||
#if __MonoCS__
|
||||
private async Task DisposeAsyncCore()
|
||||
#else
|
||||
private async ValueTask DisposeAsyncCore()
|
||||
#endif
|
||||
{
|
||||
// Same logic as in Dispose(), but with async flushing.
|
||||
Debug.Assert(GetType() == typeof(StreamWriter));
|
||||
try
|
||||
{
|
||||
if (_stream != null)
|
||||
{
|
||||
await FlushAsync().ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
CloseStreamFromDispose(disposing: true);
|
||||
}
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
private void CloseStreamFromDispose(bool disposing)
|
||||
{
|
||||
// Dispose of our resources if this StreamWriter is closable.
|
||||
if (!LeaveOpen && _stream != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Attempt to close the stream even if there was an IO error from Flushing.
|
||||
// Note that Stream.Close() can potentially throw here (may or may not be
|
||||
// due to the same Flush error). In this case, we still need to ensure
|
||||
// cleaning up internal resources, hence the finally block.
|
||||
if (disposing)
|
||||
{
|
||||
_stream.Close();
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
_stream = null;
|
||||
_byteBuffer = null;
|
||||
_charBuffer = null;
|
||||
_encoding = null;
|
||||
_encoder = null;
|
||||
_charLen = 0;
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
public override void Flush()
|
||||
{
|
||||
CheckAsyncTaskInProgress();
|
||||
|
||||
@@ -80,6 +80,21 @@ namespace System.IO
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
#if MONO // Copied from CoreFX-master (NS2.1)
|
||||
public virtual ValueTask DisposeAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
Dispose();
|
||||
return default;
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
return new ValueTask(Task.FromException(exc));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// Clears all buffers for this TextWriter and causes any buffered data to be
|
||||
// written to the underlying device. This default method is empty, but
|
||||
// descendant classes can override the method to provide the appropriate
|
||||
|
||||
149
external/corefx/src/Common/src/CoreLib/System/Index.cs
vendored
Normal file
149
external/corefx/src/Common/src/CoreLib/System/Index.cs
vendored
Normal file
@@ -0,0 +1,149 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace System
|
||||
{
|
||||
/// <summary>Represent a type can be used to index a collection either from the start or the end.</summary>
|
||||
/// <remarks>
|
||||
/// Index is used by the C# compiler to support the new index syntax
|
||||
/// <code>
|
||||
/// int[] someArray = new int[5] { 1, 2, 3, 4, 5 } ;
|
||||
/// int lastElement = someArray[^1]; // lastElement = 5
|
||||
/// </code>
|
||||
/// </remarks>
|
||||
public readonly struct Index : IEquatable<Index>
|
||||
{
|
||||
private readonly int _value;
|
||||
|
||||
/// <summary>Construct an Index using a value and indicating if the index is from the start or from the end.</summary>
|
||||
/// <param name="value">The index value. it has to be zero or positive number.</param>
|
||||
/// <param name="fromEnd">Indicating if the index is from the start or from the end.</param>
|
||||
/// <remarks>
|
||||
/// If the Index constructed from the end, index value 1 means pointing at the last element and index value 0 means pointing at beyond last element.
|
||||
/// </remarks>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public Index(int value, bool fromEnd = false)
|
||||
{
|
||||
if (value < 0)
|
||||
{
|
||||
ThrowHelper.ThrowValueArgumentOutOfRange_NeedNonNegNumException();
|
||||
}
|
||||
|
||||
if (fromEnd)
|
||||
_value = ~value;
|
||||
else
|
||||
_value = value;
|
||||
}
|
||||
|
||||
// The following private constructors mainly created for perf reason to avoid the checks
|
||||
private Index(int value)
|
||||
{
|
||||
_value = value;
|
||||
}
|
||||
|
||||
/// <summary>Create an Index pointing at first element.</summary>
|
||||
public static Index Start => new Index(0);
|
||||
|
||||
/// <summary>Create an Index pointing at beyond last element.</summary>
|
||||
public static Index End => new Index(~0);
|
||||
|
||||
/// <summary>Create an Index from the start at the position indicated by the value.</summary>
|
||||
/// <param name="value">The index value from the start.</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Index FromStart(int value)
|
||||
{
|
||||
if (value < 0)
|
||||
{
|
||||
ThrowHelper.ThrowValueArgumentOutOfRange_NeedNonNegNumException();
|
||||
}
|
||||
|
||||
return new Index(value);
|
||||
}
|
||||
|
||||
/// <summary>Create an Index from the end at the position indicated by the value.</summary>
|
||||
/// <param name="value">The index value from the end.</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Index FromEnd(int value)
|
||||
{
|
||||
if (value < 0)
|
||||
{
|
||||
ThrowHelper.ThrowValueArgumentOutOfRange_NeedNonNegNumException();
|
||||
}
|
||||
|
||||
return new Index(~value);
|
||||
}
|
||||
|
||||
/// <summary>Returns the index value.</summary>
|
||||
public int Value
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_value < 0)
|
||||
return ~_value;
|
||||
else
|
||||
return _value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Indicates whether the index is from the start or the end.</summary>
|
||||
public bool IsFromEnd => _value < 0;
|
||||
|
||||
/// <summary>Calculate the offset from the start using the giving collection length.</summary>
|
||||
/// <param name="length">The length of the collection that the Index will be used with. length has to be a positive value</param>
|
||||
/// <remarks>
|
||||
/// For performance reason, we don't validate the input length parameter and the returned offset value against negative values.
|
||||
/// we don't validate either the returned offset is greater than the input length.
|
||||
/// It is expected Index will be used with collections which always have non negative length/count. If the returned offset is negative and
|
||||
/// then used to index a collection will get out of range exception which will be same affect as the validation.
|
||||
/// </remarks>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public int GetOffset(int length)
|
||||
{
|
||||
int offset;
|
||||
|
||||
if (IsFromEnd)
|
||||
offset = length - (~_value);
|
||||
else
|
||||
offset = _value;
|
||||
|
||||
return offset;
|
||||
}
|
||||
|
||||
/// <summary>Indicates whether the current Index object is equal to another object of the same type.</summary>
|
||||
/// <param name="value">An object to compare with this object</param>
|
||||
public override bool Equals(object value) => value is Index && _value == ((Index)value)._value;
|
||||
|
||||
/// <summary>Indicates whether the current Index object is equal to another Index object.</summary>
|
||||
/// <param name="other">An object to compare with this object</param>
|
||||
public bool Equals (Index other) => _value == other._value;
|
||||
|
||||
/// <summary>Returns the hash code for this instance.</summary>
|
||||
public override int GetHashCode() => _value;
|
||||
|
||||
/// <summary>Converts integer number to an Index.</summary>
|
||||
public static implicit operator Index(int value) => FromStart(value);
|
||||
|
||||
/// <summary>Converts the value of the current Index object to its equivalent string representation.</summary>
|
||||
public override string ToString()
|
||||
{
|
||||
if (IsFromEnd)
|
||||
return ToStringFromEnd();
|
||||
|
||||
return ((uint)Value).ToString();
|
||||
}
|
||||
|
||||
private string ToStringFromEnd()
|
||||
{
|
||||
Span<char> span = stackalloc char[11]; // 1 for ^ and 10 for longest possible uint value
|
||||
bool formatted = ((uint)Value).TryFormat(span.Slice(1), out int charsWritten);
|
||||
Debug.Assert(formatted);
|
||||
span[0] = '^';
|
||||
return new string(span.Slice(0, charsWritten + 1));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -14,9 +14,9 @@ namespace System
|
||||
#if !MONO
|
||||
[TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
|
||||
#endif
|
||||
public struct Int16 : IComparable, IConvertible, IFormattable, IComparable<Int16>, IEquatable<Int16>, ISpanFormattable
|
||||
public readonly struct Int16 : IComparable, IConvertible, IFormattable, IComparable<Int16>, IEquatable<Int16>, ISpanFormattable
|
||||
{
|
||||
private short m_value; // Do not rename (binary serialization)
|
||||
private readonly short m_value; // Do not rename (binary serialization)
|
||||
|
||||
public const short MaxValue = (short)0x7FFF;
|
||||
public const short MinValue = unchecked((short)0x8000);
|
||||
|
||||
@@ -14,9 +14,9 @@ namespace System
|
||||
#if !MONO
|
||||
[TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
|
||||
#endif
|
||||
public struct Int32 : IComparable, IConvertible, IFormattable, IComparable<Int32>, IEquatable<Int32>, ISpanFormattable
|
||||
public readonly struct Int32 : IComparable, IConvertible, IFormattable, IComparable<Int32>, IEquatable<Int32>, ISpanFormattable
|
||||
{
|
||||
private int m_value; // Do not rename (binary serialization)
|
||||
private readonly int m_value; // Do not rename (binary serialization)
|
||||
|
||||
public const int MaxValue = 0x7fffffff;
|
||||
public const int MinValue = unchecked((int)0x80000000);
|
||||
|
||||
@@ -14,9 +14,9 @@ namespace System
|
||||
#if !MONO
|
||||
[TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
|
||||
#endif
|
||||
public struct Int64 : IComparable, IConvertible, IFormattable, IComparable<Int64>, IEquatable<Int64>, ISpanFormattable
|
||||
public readonly struct Int64 : IComparable, IConvertible, IFormattable, IComparable<Int64>, IEquatable<Int64>, ISpanFormattable
|
||||
{
|
||||
private long m_value; // Do not rename (binary serialization)
|
||||
private readonly long m_value; // Do not rename (binary serialization)
|
||||
|
||||
public const long MaxValue = 0x7fffffffffffffffL;
|
||||
public const long MinValue = unchecked((long)0x8000000000000000L);
|
||||
|
||||
@@ -17,13 +17,13 @@ namespace System
|
||||
{
|
||||
[Serializable]
|
||||
[System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
|
||||
public struct IntPtr : IEquatable<IntPtr>, ISerializable
|
||||
public readonly struct IntPtr : IEquatable<IntPtr>, ISerializable
|
||||
{
|
||||
// WARNING: We allow diagnostic tools to directly inspect this member (_value).
|
||||
// See https://github.com/dotnet/corert/blob/master/Documentation/design-docs/diagnostics/diagnostics-tools-contract.md for more details.
|
||||
// Please do not change the type, the name, or the semantic usage of this member without understanding the implication for tools.
|
||||
// Get in touch with the diagnostics team if you have questions.
|
||||
private unsafe void* _value; // Do not rename (binary serialization)
|
||||
private readonly unsafe void* _value; // Do not rename (binary serialization)
|
||||
|
||||
[Intrinsic]
|
||||
public static readonly IntPtr Zero;
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace System
|
||||
/// </summary>
|
||||
[DebuggerTypeProxy(typeof(MemoryDebugView<>))]
|
||||
[DebuggerDisplay("{ToString(),raw}")]
|
||||
public readonly struct Memory<T>
|
||||
public readonly struct Memory<T> : IEquatable<Memory<T>>
|
||||
{
|
||||
// NOTE: With the current implementation, Memory<T> and ReadOnlyMemory<T> must have the same layout,
|
||||
// as code uses Unsafe.As to cast between them.
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user