You've already forked linux-packaging-mono
Imported Upstream version 5.8.0.22
Former-commit-id: df344e34b07851d296efb3e6604c8db42b6f7aa3
This commit is contained in:
parent
5f4a27cc8a
commit
7d05485754
15
external/corefx/src/Common/Common.Tests.sln
vendored
15
external/corefx/src/Common/Common.Tests.sln
vendored
@@ -1,6 +1,7 @@
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 14
|
||||
VisualStudioVersion = 14.0.23107.0
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.26430.13
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Common.Tests", "tests\Common.Tests.csproj", "{C72FD34C-539A-4447-9796-62A229571199}"
|
||||
EndProject
|
||||
@@ -10,10 +11,10 @@ Global
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{C72FD34C-539A-4447-9796-62A229571199}.Debug|Any CPU.ActiveCfg = netstandard1.3-Unix-Debug|Any CPU
|
||||
{C72FD34C-539A-4447-9796-62A229571199}.Debug|Any CPU.Build.0 = netstandard1.3-Unix-Debug|Any CPU
|
||||
{C72FD34C-539A-4447-9796-62A229571199}.Release|Any CPU.ActiveCfg = netstandard1.3-Unix-Release|Any CPU
|
||||
{C72FD34C-539A-4447-9796-62A229571199}.Release|Any CPU.Build.0 = netstandard1.3-Unix-Release|Any CPU
|
||||
{C72FD34C-539A-4447-9796-62A229571199}.Debug|Any CPU.ActiveCfg = netstandard-Windows_NT-Debug|Any CPU
|
||||
{C72FD34C-539A-4447-9796-62A229571199}.Debug|Any CPU.Build.0 = netstandard-Windows_NT-Debug|Any CPU
|
||||
{C72FD34C-539A-4447-9796-62A229571199}.Release|Any CPU.ActiveCfg = netstandard-Windows_NT-Release|Any CPU
|
||||
{C72FD34C-539A-4447-9796-62A229571199}.Release|Any CPU.Build.0 = netstandard-Windows_NT-Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
@@ -145,6 +145,7 @@ internal static partial class Interop
|
||||
|
||||
case "adfs":
|
||||
case "affs":
|
||||
case "apfs":
|
||||
case "befs":
|
||||
case "bfs":
|
||||
case "btrfs":
|
||||
|
||||
@@ -49,5 +49,6 @@ internal static partial class Interop
|
||||
|
||||
internal const string OpenSsl10Description = "openssl/1.0";
|
||||
internal const string SecureTransportDescription = "SecureTransport";
|
||||
internal const string LibreSslDescription = "LibreSSL";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,9 +50,10 @@ internal static partial class Interop
|
||||
{
|
||||
SafeSslHandle context = null;
|
||||
|
||||
IntPtr method = GetSslMethod(protocols);
|
||||
|
||||
using (SafeSslContextHandle innerContext = Ssl.SslCtxCreate(method))
|
||||
// Always use SSLv23_method, regardless of protocols. It supports negotiating to the highest
|
||||
// mutually supported version and can thus handle any of the set protocols, and we then use
|
||||
// SetProtocolOptions to ensure we only allow the ones requested.
|
||||
using (SafeSslContextHandle innerContext = Ssl.SslCtxCreate(Ssl.SslMethods.SSLv23_method))
|
||||
{
|
||||
if (innerContext.IsInvalid)
|
||||
{
|
||||
@@ -231,15 +232,21 @@ internal static partial class Interop
|
||||
return retVal;
|
||||
}
|
||||
|
||||
internal static int Decrypt(SafeSslHandle context, byte[] outBuffer, int count, out Ssl.SslErrorCode errorCode)
|
||||
internal static int Decrypt(SafeSslHandle context, byte[] outBuffer, int offset, int count, out Ssl.SslErrorCode errorCode)
|
||||
{
|
||||
errorCode = Ssl.SslErrorCode.SSL_ERROR_NONE;
|
||||
|
||||
int retVal = BioWrite(context.InputBio, outBuffer, 0, count);
|
||||
int retVal = BioWrite(context.InputBio, outBuffer, offset, count);
|
||||
|
||||
if (retVal == count)
|
||||
{
|
||||
retVal = Ssl.SslRead(context, outBuffer, outBuffer.Length);
|
||||
unsafe
|
||||
{
|
||||
fixed (byte* fixedBuffer = outBuffer)
|
||||
{
|
||||
retVal = Ssl.SslRead(context, fixedBuffer + offset, outBuffer.Length);
|
||||
}
|
||||
}
|
||||
|
||||
if (retVal > 0)
|
||||
{
|
||||
@@ -303,54 +310,6 @@ internal static partial class Interop
|
||||
bindingHandle.SetCertHashLength(certHashLength);
|
||||
}
|
||||
|
||||
private static IntPtr GetSslMethod(SslProtocols protocols)
|
||||
{
|
||||
#pragma warning disable 0618 // Ssl2, Ssl3 are deprecated.
|
||||
bool ssl2 = (protocols & SslProtocols.Ssl2) == SslProtocols.Ssl2;
|
||||
bool ssl3 = (protocols & SslProtocols.Ssl3) == SslProtocols.Ssl3;
|
||||
#pragma warning restore
|
||||
bool tls10 = (protocols & SslProtocols.Tls) == SslProtocols.Tls;
|
||||
bool tls11 = (protocols & SslProtocols.Tls11) == SslProtocols.Tls11;
|
||||
bool tls12 = (protocols & SslProtocols.Tls12) == SslProtocols.Tls12;
|
||||
|
||||
IntPtr method = Ssl.SslMethods.SSLv23_method; // default
|
||||
string methodName = "SSLv23_method";
|
||||
|
||||
if (!ssl2)
|
||||
{
|
||||
if (!ssl3)
|
||||
{
|
||||
if (!tls11 && !tls12)
|
||||
{
|
||||
method = Ssl.SslMethods.TLSv1_method;
|
||||
methodName = "TLSv1_method";
|
||||
}
|
||||
else if (!tls10 && !tls12)
|
||||
{
|
||||
method = Ssl.SslMethods.TLSv1_1_method;
|
||||
methodName = "TLSv1_1_method";
|
||||
}
|
||||
else if (!tls10 && !tls11)
|
||||
{
|
||||
method = Ssl.SslMethods.TLSv1_2_method;
|
||||
methodName = "TLSv1_2_method";
|
||||
}
|
||||
}
|
||||
else if (!tls10 && !tls11 && !tls12)
|
||||
{
|
||||
method = Ssl.SslMethods.SSLv3_method;
|
||||
methodName = "SSLv3_method";
|
||||
}
|
||||
}
|
||||
|
||||
if (IntPtr.Zero == method)
|
||||
{
|
||||
throw new SslException(SR.Format(SR.net_get_ssl_method_failed, methodName));
|
||||
}
|
||||
|
||||
return method;
|
||||
}
|
||||
|
||||
private static int VerifyClientCertificate(int preverify_ok, IntPtr x509_ctx_ptr)
|
||||
{
|
||||
// Full validation is handled after the handshake in VerifyCertificateProperties and the
|
||||
|
||||
@@ -20,18 +20,6 @@ internal static partial class Interop
|
||||
[DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_SslV2_3Method")]
|
||||
internal static extern IntPtr SslV2_3Method();
|
||||
|
||||
[DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_SslV3Method")]
|
||||
internal static extern IntPtr SslV3Method();
|
||||
|
||||
[DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_TlsV1Method")]
|
||||
internal static extern IntPtr TlsV1Method();
|
||||
|
||||
[DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_TlsV1_1Method")]
|
||||
internal static extern IntPtr TlsV1_1Method();
|
||||
|
||||
[DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_TlsV1_2Method")]
|
||||
internal static extern IntPtr TlsV1_2Method();
|
||||
|
||||
[DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_SslCreate")]
|
||||
internal static extern SafeSslHandle SslCreate(SafeSslContextHandle ctx);
|
||||
|
||||
@@ -74,7 +62,7 @@ internal static partial class Interop
|
||||
internal static extern unsafe int SslWrite(SafeSslHandle ssl, byte* buf, int num);
|
||||
|
||||
[DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_SslRead")]
|
||||
internal static extern int SslRead(SafeSslHandle ssl, byte[] buf, int num);
|
||||
internal static extern unsafe int SslRead(SafeSslHandle ssl, byte* buf, int num);
|
||||
|
||||
[DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_IsSslRenegotiatePending")]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
@@ -157,10 +145,6 @@ internal static partial class Interop
|
||||
|
||||
internal static class SslMethods
|
||||
{
|
||||
internal static readonly IntPtr TLSv1_method = TlsV1Method();
|
||||
internal static readonly IntPtr TLSv1_1_method = TlsV1_1Method();
|
||||
internal static readonly IntPtr TLSv1_2_method = TlsV1_2Method();
|
||||
internal static readonly IntPtr SSLv3_method = SslV3Method();
|
||||
internal static readonly IntPtr SSLv23_method = SslV2_3Method();
|
||||
}
|
||||
|
||||
|
||||
@@ -176,6 +176,7 @@ internal static partial class Interop
|
||||
X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT = 2,
|
||||
X509_V_ERR_UNABLE_TO_GET_CRL = 3,
|
||||
X509_V_ERR_UNABLE_TO_DECRYPT_CRL_SIGNATURE = 5,
|
||||
X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY = 6,
|
||||
X509_V_ERR_CERT_SIGNATURE_FAILURE = 7,
|
||||
X509_V_ERR_CRL_SIGNATURE_FAILURE = 8,
|
||||
X509_V_ERR_CERT_NOT_YET_VALID = 9,
|
||||
|
||||
@@ -605,17 +605,6 @@ internal static partial class Interop
|
||||
[DllImport(Libraries.HttpApi, SetLastError = true)]
|
||||
internal static extern unsafe uint HttpReceiveClientCertificate(SafeHandle requestQueueHandle, ulong connectionId, uint flags, byte* pSslClientCertInfo, uint sslClientCertInfoSize, uint* pBytesReceived, NativeOverlapped* pOverlapped);
|
||||
|
||||
[Flags]
|
||||
internal enum FileCompletionNotificationModes : byte
|
||||
{
|
||||
None = 0,
|
||||
SkipCompletionPortOnSuccess = 1,
|
||||
SkipSetEventOnHandle = 2
|
||||
}
|
||||
|
||||
[DllImport(Libraries.Kernel32, SetLastError = true)]
|
||||
internal static extern unsafe bool SetFileCompletionNotificationModes(SafeHandle handle, FileCompletionNotificationModes modes);
|
||||
|
||||
internal static readonly string[] HttpVerbs = new string[]
|
||||
{
|
||||
null,
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
// 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 Microsoft.Win32.SafeHandles;
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
internal partial class Interop
|
||||
{
|
||||
internal partial class NtDll
|
||||
{
|
||||
[DllImport(Libraries.NtDll)]
|
||||
internal static extern int NtQueryInformationProcess(SafeProcessHandle processHandle, int query, NtProcessBasicInfo info, int size, int[] returnedSize);
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal class NtProcessBasicInfo
|
||||
{
|
||||
internal int ExitStatus = 0;
|
||||
internal IntPtr PebBaseAddress = (IntPtr)0;
|
||||
internal IntPtr AffinityMask = (IntPtr)0;
|
||||
internal int BasePriority = 0;
|
||||
internal IntPtr UniqueProcessId = (IntPtr)0;
|
||||
internal IntPtr InheritedFromUniqueProcessId = (IntPtr)0;
|
||||
}
|
||||
|
||||
internal const int NtQueryProcessBasicInfo = 0;
|
||||
}
|
||||
}
|
||||
@@ -7,9 +7,9 @@ using System.Runtime.InteropServices;
|
||||
|
||||
internal static partial class Interop
|
||||
{
|
||||
internal static partial class NtDll
|
||||
internal static partial class Advapi32
|
||||
{
|
||||
[DllImport(Interop.Libraries.NtDll, CharSet = CharSet.Unicode, SetLastError = true)]
|
||||
internal static extern int RtlNtStatusToDosError(int status);
|
||||
[DllImport(Interop.Libraries.Advapi32, SetLastError = false)]
|
||||
internal static extern uint LsaNtStatusToWinError(uint status);
|
||||
}
|
||||
}
|
||||
18
external/corefx/src/Common/src/Interop/Windows/kernel32/Interop.CheckTokenMembershipEx.cs
vendored
Normal file
18
external/corefx/src/Common/src/Interop/Windows/kernel32/Interop.CheckTokenMembershipEx.cs
vendored
Normal 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 Microsoft.Win32.SafeHandles;
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
internal static partial class Interop
|
||||
{
|
||||
internal static partial class Kernel32
|
||||
{
|
||||
internal const uint CTMF_INCLUDE_APPCONTAINER = 0x00000001;
|
||||
|
||||
[DllImport(Interop.Libraries.Kernel32, SetLastError = true)]
|
||||
internal static extern bool CheckTokenMembershipEx(SafeAccessTokenHandle TokenHandle, byte[] SidToCheck, uint Flags, ref bool IsMember);
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ internal partial class Interop
|
||||
{
|
||||
internal partial class Kernel32
|
||||
{
|
||||
internal static int CopyFile(String src, String dst, bool failIfExists)
|
||||
internal static int CopyFile(string src, string dst, bool failIfExists)
|
||||
{
|
||||
uint copyFlags = failIfExists ? (uint)Interop.Kernel32.FileOperations.COPY_FILE_FAIL_IF_EXISTS : 0;
|
||||
Interop.Kernel32.COPYFILE2_EXTENDED_PARAMETERS parameters = new Interop.Kernel32.COPYFILE2_EXTENDED_PARAMETERS()
|
||||
|
||||
15
external/corefx/src/Common/src/Interop/Windows/kernel32/Interop.GetProcessId.cs
vendored
Normal file
15
external/corefx/src/Common/src/Interop/Windows/kernel32/Interop.GetProcessId.cs
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
// 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 Microsoft.Win32.SafeHandles;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
internal partial class Interop
|
||||
{
|
||||
internal partial class Kernel32
|
||||
{
|
||||
[DllImport(Libraries.Kernel32)]
|
||||
public static extern int GetProcessId(SafeProcessHandle nativeHandle);
|
||||
}
|
||||
}
|
||||
@@ -2,17 +2,14 @@
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using Microsoft.Win32.SafeHandles;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using Microsoft.Win32.SafeHandles;
|
||||
|
||||
internal partial class Interop
|
||||
{
|
||||
internal partial class Kernel32
|
||||
{
|
||||
internal static readonly IntPtr INVALID_HANDLE_VALUE = new IntPtr(-1); // WinBase.h
|
||||
|
||||
/// <summary>
|
||||
/// Does not allow access to non-file devices. This disallows DOS devices like "con:", "com1:",
|
||||
/// "lpt1:", etc. Use this to avoid security problems, like allowing a web client asking a server
|
||||
@@ -20,10 +17,10 @@ internal partial class Interop
|
||||
/// </summary>
|
||||
[System.Security.SecurityCritical] // auto-generated
|
||||
internal static SafeFileHandle SafeCreateFile(
|
||||
String lpFileName,
|
||||
string lpFileName,
|
||||
int dwDesiredAccess,
|
||||
System.IO.FileShare dwShareMode,
|
||||
ref Interop.Kernel32.SECURITY_ATTRIBUTES securityAttrs,
|
||||
ref SECURITY_ATTRIBUTES securityAttrs,
|
||||
FileMode dwCreationDisposition,
|
||||
int dwFlagsAndAttributes,
|
||||
IntPtr hTemplateFile)
|
||||
@@ -32,8 +29,8 @@ internal partial class Interop
|
||||
|
||||
if (!handle.IsInvalid)
|
||||
{
|
||||
int fileType = Interop.Kernel32.GetFileType(handle);
|
||||
if (fileType != Interop.Kernel32.FileTypes.FILE_TYPE_DISK)
|
||||
int fileType = GetFileType(handle);
|
||||
if (fileType != FileTypes.FILE_TYPE_DISK)
|
||||
{
|
||||
handle.Dispose();
|
||||
throw new NotSupportedException(SR.NotSupported_FileStreamOnNonFiles);
|
||||
|
||||
@@ -1305,6 +1305,18 @@ namespace System.Net.Security
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
if (IsInvalid)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var bytes = new byte[_size];
|
||||
Marshal.Copy(handle, bytes, 0, bytes.Length);
|
||||
return BitConverter.ToString(bytes).Replace('-', ' ');
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class SafeFreeContextBufferChannelBinding_SECURITY : SafeFreeContextBufferChannelBinding
|
||||
|
||||
14
external/corefx/src/Common/src/Interop/Windows/user32/Interop.GetSysColor.cs
vendored
Normal file
14
external/corefx/src/Common/src/Interop/Windows/user32/Interop.GetSysColor.cs
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
// 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;
|
||||
|
||||
internal partial class Interop
|
||||
{
|
||||
internal partial class User32
|
||||
{
|
||||
[DllImport(Libraries.User32, SetLastError = true, CharSet = CharSet.Auto)]
|
||||
public static extern int GetSysColor(int nIndex);
|
||||
}
|
||||
}
|
||||
46
external/corefx/src/Common/src/Interop/Windows/user32/Interop.Win32SystemColors.cs
vendored
Normal file
46
external/corefx/src/Common/src/Interop/Windows/user32/Interop.Win32SystemColors.cs
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
// 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.
|
||||
|
||||
internal partial class Interop
|
||||
{
|
||||
internal partial class User32
|
||||
{
|
||||
internal enum Win32SystemColors
|
||||
{
|
||||
ActiveBorder = 0x0A,
|
||||
ActiveCaption = 0x02,
|
||||
ActiveCaptionText = 0x09,
|
||||
AppWorkspace = 0x0C,
|
||||
ButtonFace = 0x0F,
|
||||
ButtonHighlight = 0x14,
|
||||
ButtonShadow = 0x10,
|
||||
Control = 0x0F,
|
||||
ControlDark = 0x10,
|
||||
ControlDarkDark = 0x15,
|
||||
ControlLight = 0x16,
|
||||
ControlLightLight = 0x14,
|
||||
ControlText = 0x12,
|
||||
Desktop = 0x01,
|
||||
GradientActiveCaption = 0x1B,
|
||||
GradientInactiveCaption = 0x1C,
|
||||
GrayText = 0x11,
|
||||
Highlight = 0x0D,
|
||||
HighlightText = 0x0E,
|
||||
HotTrack = 0x1A,
|
||||
InactiveBorder = 0x0B,
|
||||
InactiveCaption = 0x03,
|
||||
InactiveCaptionText = 0x13,
|
||||
Info = 0x18,
|
||||
InfoText = 0x17,
|
||||
Menu = 0x04,
|
||||
MenuBar = 0x1E,
|
||||
MenuHighlight = 0x1D,
|
||||
MenuText = 0x07,
|
||||
ScrollBar = 0x00,
|
||||
Window = 0x05,
|
||||
WindowFrame = 0x06,
|
||||
WindowText = 0x08
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ namespace System
|
||||
{
|
||||
internal static bool EqualsOrdinal(string left, char[] right, int rightStartIndex, int rightLength)
|
||||
{
|
||||
Debug.Assert(left != null);
|
||||
Debug.Assert(left != null, "Expected non-null string");
|
||||
DebugAssertArrayInputs(right, rightStartIndex, rightLength);
|
||||
|
||||
if (left.Length != rightLength)
|
||||
@@ -31,7 +31,7 @@ namespace System
|
||||
|
||||
internal static bool EqualsOrdinalAsciiIgnoreCase(string left, char[] right, int rightStartIndex, int rightLength)
|
||||
{
|
||||
Debug.Assert(left != null);
|
||||
Debug.Assert(left != null, "Expected non-null string");
|
||||
DebugAssertArrayInputs(right, rightStartIndex, rightLength);
|
||||
|
||||
if (left.Length != rightLength)
|
||||
@@ -83,10 +83,10 @@ namespace System
|
||||
[Conditional("DEBUG")]
|
||||
internal static void DebugAssertArrayInputs(char[] array, int startIndex, int length)
|
||||
{
|
||||
Debug.Assert(array != null);
|
||||
Debug.Assert(startIndex >= 0);
|
||||
Debug.Assert(length >= 0);
|
||||
Debug.Assert(startIndex <= array.Length - length);
|
||||
Debug.Assert(array != null, "Null array");
|
||||
Debug.Assert(startIndex >= 0, $"Expected {nameof(startIndex)} to be >= 0, got {startIndex}");
|
||||
Debug.Assert(length >= 0, $"Expected {nameof(length)} to be >= 0, got {length}");
|
||||
Debug.Assert(startIndex <= array.Length - length, $"Expected {startIndex} to be <= {array.Length} - {length}, got {startIndex}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,18 +23,15 @@ namespace System.Collections.Generic
|
||||
{
|
||||
Debug.Assert(source != null);
|
||||
|
||||
var collection = source as ICollection<T>;
|
||||
if (collection != null)
|
||||
if (source is ICollection<T> collection)
|
||||
{
|
||||
count = collection.Count;
|
||||
return true;
|
||||
}
|
||||
|
||||
var provider = source as IIListProvider<T>;
|
||||
if (provider != null)
|
||||
if (source is IIListProvider<T> provider)
|
||||
{
|
||||
count = provider.GetCount(onlyIfCheap: true);
|
||||
return count >= 0;
|
||||
return (count = provider.GetCount(onlyIfCheap: true)) >= 0;
|
||||
}
|
||||
|
||||
count = -1;
|
||||
|
||||
@@ -26,8 +26,7 @@ namespace System.Collections.Generic
|
||||
Debug.Assert(count >= 0);
|
||||
Debug.Assert(array?.Length - arrayIndex >= count);
|
||||
|
||||
var collection = source as ICollection<T>;
|
||||
if (collection != null)
|
||||
if (source is ICollection<T> collection)
|
||||
{
|
||||
Debug.Assert(collection.Count == count);
|
||||
collection.CopyTo(array, arrayIndex);
|
||||
@@ -68,8 +67,7 @@ namespace System.Collections.Generic
|
||||
{
|
||||
Debug.Assert(source != null);
|
||||
|
||||
var collection = source as ICollection<T>;
|
||||
if (collection != null)
|
||||
if (source is ICollection<T> collection)
|
||||
{
|
||||
int count = collection.Count;
|
||||
if (count == 0)
|
||||
@@ -96,8 +94,7 @@ namespace System.Collections.Generic
|
||||
/// </returns>
|
||||
internal static T[] ToArray<T>(IEnumerable<T> source, out int length)
|
||||
{
|
||||
ICollection<T> ic = source as ICollection<T>;
|
||||
if (ic != null)
|
||||
if (source is ICollection<T> ic)
|
||||
{
|
||||
int count = ic.Count;
|
||||
if (count != 0)
|
||||
|
||||
@@ -266,8 +266,7 @@ namespace System.Collections.Generic
|
||||
/// </summary>
|
||||
public T[] ToArray()
|
||||
{
|
||||
T[] array;
|
||||
if (TryMove(out array))
|
||||
if (TryMove(out T[] array))
|
||||
{
|
||||
// No resizing to do.
|
||||
return array;
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user