Imported Upstream version 6.0.0.172

Former-commit-id: f3cc9b82f3e5bd8f0fd3ebc098f789556b44e9cd
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2019-04-12 14:10:50 +00:00
parent 8016999e4d
commit 64ac736ec5
32155 changed files with 3981439 additions and 75368 deletions

View File

@@ -3,100 +3,66 @@
// See the LICENSE file in the project root for more information.
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading;
using Microsoft.Win32.SafeHandles;
using System.Text;
internal static partial class Interop
{
internal static partial class Sys
{
private static readonly int s_readBufferSize = GetReadDirRBufferSize();
internal enum NodeType : int
{
DT_UNKNOWN = 0,
DT_FIFO = 1,
DT_CHR = 2,
DT_DIR = 4,
DT_BLK = 6,
DT_REG = 8,
DT_LNK = 10,
DT_SOCK = 12,
DT_WHT = 14
DT_UNKNOWN = 0,
DT_FIFO = 1,
DT_CHR = 2,
DT_DIR = 4,
DT_BLK = 6,
DT_REG = 8,
DT_LNK = 10,
DT_SOCK = 12,
DT_WHT = 14
}
[StructLayout(LayoutKind.Sequential)]
private unsafe struct InternalDirectoryEntry
internal unsafe struct DirectoryEntry
{
internal IntPtr Name;
internal int NameLength;
internal NodeType InodeType;
}
internal byte* Name;
internal int NameLength;
internal NodeType InodeType;
internal const int NameBufferSize = 256;
internal struct DirectoryEntry
{
internal NodeType InodeType;
internal string InodeName;
internal ReadOnlySpan<char> GetName(Span<char> buffer)
{
Debug.Assert(buffer.Length >= Encoding.UTF8.GetMaxCharCount(NameBufferSize - 1), "should have enough space for the max file name");
Debug.Assert(Name != null, "should not have a null name");
ReadOnlySpan<byte> nameBytes = (NameLength == -1)
// In this case the struct was allocated via struct dirent *readdir(DIR *dirp);
? new ReadOnlySpan<byte>(Name, new ReadOnlySpan<byte>(Name, NameBufferSize - 1).IndexOf<byte>(0))
: new ReadOnlySpan<byte>(Name, NameLength);
Debug.Assert(nameBytes.Length > 0, "we shouldn't have gotten a garbage value from the OS");
if (nameBytes.Length == 0)
return buffer.Slice(0, 0);
int charCount = Encoding.UTF8.GetChars(nameBytes, buffer);
ReadOnlySpan<char> value = buffer.Slice(0, charCount);
Debug.Assert(NameLength != -1 || !value.Contains('\0'), "should not have embedded nulls if we parsed the end of string");
return value;
}
}
[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_OpenDir", SetLastError = true)]
internal static extern Microsoft.Win32.SafeHandles.SafeDirectoryHandle OpenDir(string path);
internal static extern IntPtr OpenDir(string path);
[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetReadDirRBufferSize", SetLastError = false)]
internal static extern int GetReadDirRBufferSize();
[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_ReadDirR", SetLastError = false)]
private static extern unsafe int ReadDirR(IntPtr dir, byte* buffer, int bufferSize, out InternalDirectoryEntry outputEntry);
internal static extern unsafe int ReadDirR(IntPtr dir, byte* buffer, int bufferSize, out DirectoryEntry outputEntry);
[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_CloseDir", SetLastError = true)]
internal static extern int CloseDir(IntPtr dir);
// The calling pattern for ReadDir is described in src/Native/System.Native/pal_readdir.cpp
internal static int ReadDir(SafeDirectoryHandle dir, out DirectoryEntry outputEntry)
{
bool addedRef = false;
try
{
// We avoid a native string copy into InternalDirectoryEntry.
// - If the platform suppors reading into a buffer, the data is read directly into the buffer. The
// data can be read as long as the buffer is valid.
// - If the platform does not support reading into a buffer, the information returned in
// InternalDirectoryEntry points to native memory owned by the SafeDirectoryHandle. The data is only
// valid until the next call to CloseDir/ReadDir. We extend the reference until we have copied all data
// to ensure it does not become invalid by a CloseDir; and we copy the data so our caller does not
// use the native memory held by the SafeDirectoryHandle.
dir.DangerousAddRef(ref addedRef);
unsafe
{
// s_readBufferSize is zero when the native implementation does not support reading into a buffer.
byte* buffer = stackalloc byte[s_readBufferSize];
InternalDirectoryEntry temp;
int ret = ReadDirR(dir.DangerousGetHandle(), buffer, s_readBufferSize, out temp);
// We copy data into DirectoryEntry to ensure there are no dangling references.
outputEntry = ret == 0 ?
new DirectoryEntry() { InodeName = GetDirectoryEntryName(temp), InodeType = temp.InodeType } :
default(DirectoryEntry);
return ret;
}
}
finally
{
if (addedRef)
{
dir.DangerousRelease();
}
}
}
private static unsafe string GetDirectoryEntryName(InternalDirectoryEntry dirEnt)
{
if (dirEnt.NameLength == -1)
return Marshal.PtrToStringAnsi(dirEnt.Name);
else
return Marshal.PtrToStringAnsi(dirEnt.Name, dirEnt.NameLength);
}
}
}
}

View File

@@ -60,6 +60,8 @@
<Compile Include="$(MSBuildThisFileDirectory)System\Collections\Comparer.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Collections\DictionaryEntry.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Collections\Generic\Dictionary.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Collections\Generic\IAsyncEnumerable.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Collections\Generic\IAsyncEnumerator.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Collections\Generic\ICollection.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Collections\Generic\ICollectionDebugView.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Collections\Generic\IComparer.cs" />
@@ -187,6 +189,7 @@
<Compile Include="$(MSBuildThisFileDirectory)System\Guid.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\HashCode.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\HResults.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\IAsyncDisposable.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\IAsyncResult.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\ICloneable.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\IComparable.cs" />
@@ -372,6 +375,8 @@
<Compile Include="$(MSBuildThisFileDirectory)System\Resources\SatelliteContractVersionAttribute.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Resources\UltimateResourceFallbackLocation.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\AccessedThroughPropertyAttribute.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\AsyncIteratorStateMachineAttribute.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\AsyncIteratorMethodBuilder.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\AsyncMethodBuilderAttribute.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\AsyncStateMachineAttribute.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\AsyncValueTaskMethodBuilder.cs" />
@@ -382,6 +387,8 @@
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\CompilationRelaxationsAttribute.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\CompilerGeneratedAttribute.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\CompilerGlobalScopeAttribute.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\ConfiguredAsyncDisposable.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\ConfiguredCancelableAsyncEnumerable.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\ConfiguredValueTaskAwaitable.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\CustomConstantAttribute.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\DateTimeConstantAttribute.cs" />
@@ -543,6 +550,7 @@
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\DeferredDisposableLifetime.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\EventResetMode.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\ExecutionContext.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\IThreadPoolWorkItem.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\LazyInitializer.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\LazyThreadSafetyMode.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\LockRecursionException.cs" />
@@ -559,6 +567,7 @@
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\Tasks\TaskToApm.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\Tasks\TaskSchedulerException.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\Tasks\ValueTask.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\Tasks\Sources\ManualResetValueTaskSourceCore.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\Tasks\Sources\IValueTaskSource.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\ThreadAbortException.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\ThreadPriority.cs" />

View File

@@ -0,0 +1,18 @@
// 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.Threading;
namespace System.Collections.Generic
{
/// <summary>Exposes an enumerator that provides asynchronous iteration over values of a specified type.</summary>
/// <typeparam name="T">The type of values to enumerate.</typeparam>
public interface IAsyncEnumerable<out T>
{
/// <summary>Returns an enumerator that iterates asynchronously through the collection.</summary>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> that may be used to cancel the asynchronous iteration.</param>
/// <returns>An enumerator that can be used to iterate asynchronously through the collection.</returns>
IAsyncEnumerator<T> GetAsyncEnumerator(CancellationToken cancellationToken = default);
}
}

View File

@@ -0,0 +1,24 @@
// 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.Threading.Tasks;
namespace System.Collections.Generic
{
/// <summary>Supports a simple asynchronous iteration over a generic collection.</summary>
/// <typeparam name="T">The type of objects to enumerate.</typeparam>
public interface IAsyncEnumerator<out T> : IAsyncDisposable
{
/// <summary>Advances the enumerator asynchronously to the next element of the collection.</summary>
/// <returns>
/// A <see cref="ValueTask{Boolean}"/> that will complete with a result of <c>true</c> if the enumerator
/// was successfully advanced to the next element, or <c>false</c> if the enumerator has passed the end
/// of the collection.
/// </returns>
ValueTask<bool> MoveNextAsync();
/// <summary>Gets the element in the collection at the current position of the enumerator.</summary>
T Current { get; }
}
}

View File

@@ -462,6 +462,7 @@ 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);
// This is a flag to indicate if we are formating hour/minute/second only.
bool bTimeOnly = true;
@@ -653,7 +654,19 @@ namespace System
int year = cal.GetYear(dateTime);
tokenLen = ParseRepeatPattern(format, i, ch);
if (dtfi.HasForceTwoDigitYears)
if (isJapaneseCalendar &&
!AppContextSwitches.FormatJapaneseFirstYearAsANumber &&
year == 1 &&
i + tokenLen < format.Length - 1 &&
format[i + tokenLen] == '\'' &&
format[i + tokenLen + 1] == DateTimeFormatInfoScanner.CJKYearSuff[0])
{
// We are formatting a Japanese date with year equals 1 and the year number is followed by the year sign \u5e74
// In Japanese dates, the first year in the era is not formatted as a number 1 instead it is formatted as \u5143 which means
// first or beginning of the era.
result.Append(DateTimeFormatInfo.JapaneseEraStart[0]);
}
else if (dtfi.HasForceTwoDigitYears)
{
FormatDigits(result, year, tokenLen <= 2 ? tokenLen : 2);
}

View File

@@ -1 +1 @@
69bc2d672d3fa08d33dac7ed1dd7328169f5d16d
314120f3cfcb0de6415530f7dca52ec5e4bc7a90

View File

@@ -1 +1 @@
840ef7d4d277306043f86562f9cd7df1ea63583b
0dccb4fcb01a2b425dc04ac71bbc7969ad7c2326

View File

@@ -0,0 +1,18 @@
// 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.Threading.Tasks;
namespace System
{
/// <summary>Provides a mechanism for releasing unmanaged resources asynchronously.</summary>
public interface IAsyncDisposable
{
/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or
/// resetting unmanaged resources asynchronously.
/// </summary>
ValueTask DisposeAsync();
}
}

View File

@@ -23,7 +23,11 @@ namespace System.IO
// write perf. Note that for UTF-8, we end up allocating a 4K byte buffer,
// which means we take advantage of adaptive buffering code.
// The performance using UnicodeEncoding is acceptable.
#if MONO
internal const int DefaultBufferSize = 1024; // char[]
#else
private const int DefaultBufferSize = 1024; // char[]
#endif
private const int DefaultFileStreamBufferSize = 4096;
private const int MinBufferSize = 128;
@@ -70,8 +74,11 @@ namespace System.IO
// Even Close() will hit the exception as it would try to flush the unwritten data.
// Maybe we can add a DiscardBufferedData() method to get out of such situation (like
// StreamReader though for different reason). Either way, the buffered data will be lost!
#if !MONO
private static Encoding UTF8NoBOM => EncodingCache.UTF8NoBOM;
#else
private static Encoding UTF8NoBOM => EncodingHelper.UTF8Unmarked;
#endif
internal StreamWriter() : base(null)
{ // Ask for CurrentCulture all the time

View File

@@ -19,7 +19,11 @@ namespace System.Reflection
public virtual Guid ModuleVersionId { get { throw NotImplemented.ByDesign; } }
public virtual string ScopeName { get { throw NotImplemented.ByDesign; } }
public ModuleHandle ModuleHandle => GetModuleHandleImpl();
#if MONO // make internal as it's CoreRT change only
internal virtual ModuleHandle GetModuleHandleImpl() => ModuleHandle.EmptyHandle;
#else
protected virtual ModuleHandle GetModuleHandleImpl() => ModuleHandle.EmptyHandle; // Not an api but declared protected because of Reflection.Core/Corelib divide (when built by CoreRt)
#endif
public virtual void GetPEKind(out PortableExecutableKinds peKind, out ImageFileMachine machine) { throw NotImplemented.ByDesign; }
public virtual bool IsResource() { throw NotImplemented.ByDesign; }

View File

@@ -10,11 +10,25 @@ namespace System.Reflection
{
internal sealed class SignatureConstructedGenericType : SignatureType
{
internal SignatureConstructedGenericType(Type genericTypeDefinition, Type[] genericTypeArguments)
// The exception-visible name "typeArguments" is chosen to match the parameter name to Type.MakeGenericType() since that's the
// intended user of this constructor.
internal SignatureConstructedGenericType(Type genericTypeDefinition, Type[] typeArguments)
{
Debug.Assert(genericTypeDefinition != null && genericTypeArguments != null);
if (genericTypeDefinition == null)
throw new ArgumentNullException(nameof(genericTypeDefinition));
if (typeArguments == null)
throw new ArgumentNullException(nameof(typeArguments));
typeArguments = (Type[])(typeArguments.Clone());
for (int i = 0; i < typeArguments.Length; i++)
{
if (typeArguments[i] == null)
throw new ArgumentNullException(nameof(typeArguments));
}
_genericTypeDefinition = genericTypeDefinition;
_genericTypeArguments = (Type[])(genericTypeArguments.Clone());
_genericTypeArguments = typeArguments;
}
public sealed override bool IsTypeDefinition => false;

View File

@@ -0,0 +1,75 @@
// 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.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
namespace System.Runtime.CompilerServices
{
/// <summary>Represents a builder for asynchronous iterators.</summary>
[StructLayout(LayoutKind.Auto)]
public struct AsyncIteratorMethodBuilder
{
// AsyncIteratorMethodBuilder is used by the language compiler as part of generating
// async iterators. For now, the implementation just wraps AsyncTaskMethodBuilder, as
// most of the logic is shared. However, in the future this could be changed and
// optimized. For example, we do need to allocate an object (once) to flow state like
// ExecutionContext, which AsyncTaskMethodBuilder handles, but it handles it by
// allocating a Task-derived object. We could optimize this further by removing
// the Task from the hierarchy, but in doing so we'd also lose a variety of optimizations
// related to it, so we'd need to replicate all of those optimizations (e.g. storing
// that box object directly into a Task's continuation field).
private AsyncTaskMethodBuilder _methodBuilder; // mutable struct; do not make it readonly
/// <summary>Creates an instance of the <see cref="AsyncIteratorMethodBuilder"/> struct.</summary>
/// <returns>The initialized instance.</returns>
public static AsyncIteratorMethodBuilder Create() =>
#if CORERT
// corert's AsyncTaskMethodBuilder.Create() currently does additional debugger-related
// work, so we need to delegate to it.
new AsyncIteratorMethodBuilder() { _methodBuilder = AsyncTaskMethodBuilder.Create() };
#else
default; // coreclr's AsyncTaskMethodBuilder.Create just returns default as well
#endif
/// <summary>Invokes <see cref="IAsyncStateMachine.MoveNext"/> on the state machine while guarding the <see cref="ExecutionContext."/></summary>
/// <typeparam name="TStateMachine">The type of the state machine.</typeparam>
/// <param name="stateMachine">The state machine instance, passed by reference.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void MoveNext<TStateMachine>(ref TStateMachine stateMachine) where TStateMachine : IAsyncStateMachine =>
#if CORERT
_methodBuilder.Start(ref stateMachine);
#else
AsyncMethodBuilderCore.Start(ref stateMachine);
#endif
/// <summary>Schedules the state machine to proceed to the next action when the specified awaiter completes.</summary>
/// <typeparam name="TAwaiter">The type of the awaiter.</typeparam>
/// <typeparam name="TStateMachine">The type of the state machine.</typeparam>
/// <param name="awaiter">The awaiter.</param>
/// <param name="stateMachine">The state machine.</param>
public void AwaitOnCompleted<TAwaiter, TStateMachine>(ref TAwaiter awaiter, ref TStateMachine stateMachine)
where TAwaiter : INotifyCompletion
where TStateMachine : IAsyncStateMachine =>
_methodBuilder.AwaitOnCompleted(ref awaiter, ref stateMachine);
/// <summary>Schedules the state machine to proceed to the next action when the specified awaiter completes.</summary>
/// <typeparam name="TAwaiter">The type of the awaiter.</typeparam>
/// <typeparam name="TStateMachine">The type of the state machine.</typeparam>
/// <param name="awaiter">The awaiter.</param>
/// <param name="stateMachine">The state machine.</param>
public void AwaitUnsafeOnCompleted<TAwaiter, TStateMachine>(ref TAwaiter awaiter, ref TStateMachine stateMachine)
where TAwaiter : ICriticalNotifyCompletion
where TStateMachine : IAsyncStateMachine =>
_methodBuilder.AwaitUnsafeOnCompleted(ref awaiter, ref stateMachine);
/// <summary>Marks iteration as being completed, whether successfully or otherwise.</summary>
public void Complete() => _methodBuilder.SetResult();
/// <summary>Gets an object that may be used to uniquely identify this builder to the debugger.</summary>
internal object ObjectIdForDebugger => _methodBuilder.ObjectIdForDebugger;
}
}

View File

@@ -0,0 +1,18 @@
// 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.
namespace System.Runtime.CompilerServices
{
/// <summary>Indicates whether a method is an asynchronous iterator.</summary>
[AttributeUsage(AttributeTargets.Method, Inherited = false, AllowMultiple = false)]
public sealed class AsyncIteratorStateMachineAttribute : StateMachineAttribute
{
/// <summary>Initializes a new instance of the <see cref="AsyncIteratorStateMachineAttribute"/> class.</summary>
/// <param name="stateMachineType">The type object for the underlying state machine type that's used to implement a state machine method.</param>
public AsyncIteratorStateMachineAttribute(Type stateMachineType)
: base(stateMachineType)
{
}
}
}

View File

@@ -0,0 +1,27 @@
// 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.Runtime.InteropServices;
namespace System.Runtime.CompilerServices
{
/// <summary>Provides a type that can be used to configure how awaits on an <see cref="IAsyncDisposable"/> are performed.</summary>
[StructLayout(LayoutKind.Auto)]
public readonly struct ConfiguredAsyncDisposable
{
private readonly IAsyncDisposable _source;
private readonly bool _continueOnCapturedContext;
internal ConfiguredAsyncDisposable(IAsyncDisposable source, bool continueOnCapturedContext)
{
_source = source;
_continueOnCapturedContext = continueOnCapturedContext;
}
public ConfiguredValueTaskAwaitable DisposeAsync() =>
// as with other "configured" awaitable-related type in CompilerServices, we don't null check to defend against
// misuse like `default(ConfiguredAsyncDisposable).DisposeAsync()`, which will null ref by design.
_source.DisposeAsync().ConfigureAwait(_continueOnCapturedContext);
}
}

View File

@@ -0,0 +1,78 @@
// 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.Collections.Generic;
using System.Runtime.InteropServices;
using System.Threading;
namespace System.Runtime.CompilerServices
{
/// <summary>Provides an awaitable async enumerable that enables cancelable iteration and configured awaits.</summary>
[StructLayout(LayoutKind.Auto)]
public readonly struct ConfiguredCancelableAsyncEnumerable<T>
{
private readonly IAsyncEnumerable<T> _enumerable;
private readonly CancellationToken _cancellationToken;
private readonly bool _continueOnCapturedContext;
internal ConfiguredCancelableAsyncEnumerable(IAsyncEnumerable<T> enumerable, bool continueOnCapturedContext, CancellationToken cancellationToken)
{
_enumerable = enumerable;
_continueOnCapturedContext = continueOnCapturedContext;
_cancellationToken = cancellationToken;
}
/// <summary>Configures how awaits on the tasks returned from an async iteration will be performed.</summary>
/// <param name="continueOnCapturedContext">Whether to capture and marshal back to the current context.</param>
/// <returns>The configured enumerable.</returns>
/// <remarks>This will replace any previous value set by <see cref="ConfigureAwait(bool)"/> for this iteration.</remarks>
public ConfiguredCancelableAsyncEnumerable<T> ConfigureAwait(bool continueOnCapturedContext) =>
new ConfiguredCancelableAsyncEnumerable<T>(_enumerable, continueOnCapturedContext, _cancellationToken);
/// <summary>Sets the <see cref="CancellationToken"/> to be passed to <see cref="IAsyncEnumerable{T}.GetAsyncEnumerator(CancellationToken)"/> when iterating.</summary>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to use.</param>
/// <returns>The configured enumerable.</returns>
/// <remarks>This will replace any previous <see cref="CancellationToken"/> set by <see cref="WithCancellation(CancellationToken)"/> for this iteration.</remarks>
public ConfiguredCancelableAsyncEnumerable<T> WithCancellation(CancellationToken cancellationToken) =>
new ConfiguredCancelableAsyncEnumerable<T>(_enumerable, _continueOnCapturedContext, cancellationToken);
public Enumerator GetAsyncEnumerator() =>
// as with other "configured" awaitable-related type in CompilerServices, we don't null check to defend against
// misuse like `default(ConfiguredCancelableAsyncEnumerable<T>).GetAsyncEnumerator()`, which will null ref by design.
new Enumerator(_enumerable.GetAsyncEnumerator(_cancellationToken), _continueOnCapturedContext);
/// <summary>Provides an awaitable async enumerator that enables cancelable iteration and configured awaits.</summary>
[StructLayout(LayoutKind.Auto)]
public readonly struct Enumerator
{
private readonly IAsyncEnumerator<T> _enumerator;
private readonly bool _continueOnCapturedContext;
internal Enumerator(IAsyncEnumerator<T> enumerator, bool continueOnCapturedContext)
{
_enumerator = enumerator;
_continueOnCapturedContext = continueOnCapturedContext;
}
/// <summary>Advances the enumerator asynchronously to the next element of the collection.</summary>
/// <returns>
/// A <see cref="ConfiguredValueTaskAwaitable{Boolean}"/> that will complete with a result of <c>true</c>
/// if the enumerator was successfully advanced to the next element, or <c>false</c> if the enumerator has
/// passed the end of the collection.
/// </returns>
public ConfiguredValueTaskAwaitable<bool> MoveNextAsync() =>
_enumerator.MoveNextAsync().ConfigureAwait(_continueOnCapturedContext);
/// <summary>Gets the element in the collection at the current position of the enumerator.</summary>
public T Current => _enumerator.Current;
/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or
/// resetting unmanaged resources asynchronously.
/// </summary>
public ConfiguredValueTaskAwaitable DisposeAsync() =>
_enumerator.DisposeAsync().ConfigureAwait(_continueOnCapturedContext);
}
}
}

View File

@@ -11,6 +11,9 @@ using System.Threading;
namespace System.Text
{
#if MONO
[Serializable]
#endif
internal sealed class InternalDecoderBestFitFallback : DecoderFallback
{
// Our variables

View File

@@ -12,6 +12,9 @@ using System.Threading;
namespace System.Text
{
#if MONO
[Serializable]
#endif
internal class InternalEncoderBestFitFallback : EncoderFallback
{
// Our variables

View File

@@ -29,6 +29,12 @@ namespace System.Text
}
#if MONO
internal Latin1Encoding(SerializationInfo info, StreamingContext context) :
base(Encoding.ISO_8859_1)
{
DeserializeEncoding(info, context);
}
// ISerializable implementation, serialize it as a CodePageEncoding
[System.Security.SecurityCritical] // auto-generated_required
void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)

View File

@@ -1183,6 +1183,9 @@ namespace System.Text
CodePage + (_emitUTF32ByteOrderMark ? 4 : 0) + (_bigEndian ? 8 : 0);
}
#if MONO
[Serializable]
#endif
private sealed class UTF32Decoder : DecoderNLS
{
// Need a place to store any extra bytes we may have picked up

View File

@@ -785,6 +785,9 @@ namespace System.Text
// Of all the amazing things... This MUST be Decoder so that our com name
// for System.Text.Decoder doesn't change
#if MONO
[Serializable]
#endif
private sealed class Decoder : DecoderNLS
{
/*private*/
@@ -822,6 +825,9 @@ namespace System.Text
// Of all the amazing things... This MUST be Encoder so that our com name
// for System.Text.Encoder doesn't change
#if MONO
[Serializable]
#endif
private sealed class Encoder : EncoderNLS
{
/*private*/
@@ -854,6 +860,9 @@ namespace System.Text
// Preexisting UTF7 behavior for bad bytes was just to spit out the byte as the next char
// and turn off base64 mode if it was in that mode. We still exit the mode, but now we fallback.
#if MONO
[Serializable]
#endif
private sealed class DecoderUTF7Fallback : DecoderFallback
{
// Construction. Default replacement fallback uses no best fit and ? replacement string

Some files were not shown because too many files have changed in this diff Show More